No VAL Command?

BlitzPlus Forums/BlitzPlus Programming/No VAL Command?

Cold Harbour(Posted 2003) [#1]
Hi there.

I need to convert a string into a number so I can do some arithmetic on the resulting number. Normally in Basic I'd use the VAL command but Blitz does not have it.

So I have an array with loads of string values like "167252", "6737367", "3738783" etc. Then I need to plug these numbers into a algoithm so they must be integers.

Can anyone tell me how I do this without the VAL command?

Thanks.


skn3(Posted 2003) [#2]
Int( value )
Parameters
value = a number, or a string which represents a number

should help :)


Cold Harbour(Posted 2003) [#3]
Doh, thanks skn, int means something else in the other basic's I've seen so I didn't make the connection.

So what about if it was an float number. How do I convert A$="2.7182" into 2.7182?

Cheers


Skitchy(Posted 2003) [#4]
Check the code archives. Theres a val function in there somewhere ;)


Cold Harbour(Posted 2003) [#5]
Hmmm, turns out there's a 'float' command that sort of does what VAL does.

I'm going to sneak away and pretend this thread didn't happen :-)


JaviCervera(Posted 2003) [#6]
you don't need a Val function. The string "2.7182" is automatically converted into the floating number 2.7182 when you assing the string to a float variable, and would be converted to 2 if you assign it to an integer variable.


Koriolis(Posted 2003) [#7]
Jedive is right.
Just a note: using Int will mess up the thing, cause Int rounds the value: Int(5.7) gives you 6 instead of 5, so it would be more correct to use Floor (but again, the conversion is automatic so no need for any of them). I mean, don't do
i% = Int(5.7)
if you expect i to be 5! This can sound like a silly advice, but you can easily spend hours debugging your code just because you thought Int just convert to int like any other language do (ie by just cutting the fractional part).


Hotcakes(Posted 2003) [#8]
Int() replaces Val() except it rounds down the string's value. Float() will convert a string to a float. "This is the same as Blitz's automatic type conversion."

Have a read of your manual some time =]


CdrJameson(Posted 2003) [#9]
I've just done the same thing looking for the Val command. Good job I found this thread. Perhaps a note in the help under 'val' would be handy.


Shagwana(Posted 2003) [#10]
Its in the FAQ!.