How to input a floating point number in Ruby | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to input a floating point number in Ruby

7th Dec 2016, 10:56 PM
School Dog
2 Answers
+ 4
This works: var = gets.chomp.to_f print var just add "to_f" (to float) function and viola! you can even operate with other floats.
8th Dec 2016, 12:20 AM
Nahuel
Nahuel - avatar
+ 2
This works too: x=gets.to_f puts x
8th Dec 2016, 1:25 AM
Project2501
Project2501 - avatar