Inconsistent output from Float#to_s

irb(main):002:0> 5.0.to_s
=> “5.0”
irb(main):003:0> 5.000000000000007.to_s
=> “5.00000000000001”
irb(main):004:0> 5.0000000000000007.to_s
=> “5”
irb(main):005:0> 5.00000000000000007.to_s
=> “5.0”

I came across this while printing the output of a function across
a range of values. I was befuddled as to why ruby would not print
a decimal point for certain float values.

Is there some rationale behind it? I expected a stringified Float
to always contain a decimal point.

···

Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢