🏢 PlaceMaker | 25% off for February including new Google Earth data imports!
Learn more
Convert a String to Float
-
i want to read a number from a text file on my hard drive, containing only this number
i wrote this
hcal = IO.read("C;\\...txt").chomp hcal.to_f
but when i check
hcal.class
hcal is still a string, not a float...
can you tell me where is my mistake?
-
hcal = IO.read("file.txt").strip.to_f
-
hcal.to_f
doesn't modifyhcal
, it returns a float. So you need to write it like so:hcal = hcal.to_f
-
@thomthom said:
hcal.to_f
doesn't modifyhcal
, it returns a float. So you need to write it like so:hcal = hcal.to_f
thanks to both you...
yes, both codes work nicely; i spent 3 hours to look for a solution, and i get 2 different, in a few minutes, on sketchucation...
learning ruby on the internet is an exciting experience
Advertisement