How to convert a number to a float

Community Forums/General Help/How to convert a number to a float

Blitzplotter(Posted 2010) [#1]
Heres my dilemma, erm its not a number to start with it is numbers within a string that I have extracted the numbers from surrounding ascii chars.

I have a number that is -0.3456789

When I attempt to convert it to a float for storing in an array (to eventually write to a file) the following fails to extract the number (just gets a zero):-

vallong=Float(long$)


I am suspecting that the Float type conversion is failing to detect the -ve in front .....


Ross C(Posted 2010) [#2]
s$ = "0.44"

d# = s$

Print d#


Works in blitz3d. It's probably because your not setting vallong to a float via the #?


Blitzplotter(Posted 2010) [#3]
Yeess, Ross C your the man! Incidentally its a lat or a long, now to do a little lat/long conversion to some cartesian co-ordinates, work out the difference between the max and the min & plot some co-ords accordingly on a map.


Blitzplotter(Posted 2010) [#4]
Hmm, now I'm trying to store the signed float in an array, is this possible? If not then I'll simply need to store the -0.1234354657 to file as a string... But it'd be really handy to dim an array to hold a float. Not sure if possible though. Am loathe to make a protracted string manipulation but I might have to.


Ross C(Posted 2010) [#5]
You'd need to dim a # array:

Dim array#(10)

array(5) = 0.54

array(6) = 5

Print array(5)
Print array(6)



Blitzplotter(Posted 2010) [#6]
Thanks RossC, you are most definitely the man!


TaskMaster(Posted 2010) [#7]
All of those problems go away if you use SuperStrict.


big10p(Posted 2010) [#8]
Blitz3D doesn't have SuperStrict.


Blitzplotter(Posted 2010) [#9]
@big10p, good point - thanks anyway Taskmaster.


TaskMaster(Posted 2010) [#10]
Whoops, didn't realize it was Blitz3D. That'll teach me not to read signatures. :)