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_fbut when i check
hcal.classhcal 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_fdoesn't modifyhcal, it returns a float. So you need to write it like so:hcal = hcal.to_f -
@thomthom said:
hcal.to_fdoesn't modifyhcal, it returns a float. So you need to write it like so:hcal = hcal.to_fthanks 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement