From: Stefan Rusterholz Date: 2007-09-03T19:57:11+09:00 Subject: Re: 0.06 == 0.06 returns false in Ruby? Matthias W辰chter wrote: > I don't understand why Ruby 'rounds' values with .inspect (and > .to_s) opposed to Marshal.dump. Compare its output with the one > Python gives (this code is for Ruby 1.8.6): Because for an *inspection* a precision of 5, 6 places are sufficient. Inspect isn't used for printing values other than debugging etc. In the opposite, having 40+ places for every float in your debug output would be rather annoying and almost always of little help. If python choses to be annoying, be it so, I'm happy ruby doesn't. Use sprintf/String#% if you want to specify the precision you want your output. Marshal.dump on the other hand is serializing, of course you don't want your floats truncated just because you're serializing. As for having a way: you can always open the Float class and define .to_s to your liking. Same for inspect. Regards Stefan -- Posted via http://www.ruby-forum.com/.