-2

When I convert string to float, how do I put a dot two houses before the end? This is a example of what I want to do.

"000001909".to_f  = 19.09

But I only get this:

"000001909".to_f  = 1909.0
sawa
  • 165,429
  • 45
  • 277
  • 381
LucasMelo
  • 97
  • 1
  • 9

1 Answers1

4

That string represents the value 1909 so merely to_fing it won't work. You need to divide by 100.0 to move the decimal point over two "houses" as you so eloquently put it:

"000001909".to_f / 100.0 # => 19.09

Having a string with a dot in it will output the expected result as well:

"0000019.09".to_f # => 19.09
DiegoSalazar
  • 13,361
  • 2
  • 38
  • 55