From: Roger Pack Date: 2010-04-10T04:55:26+09:00 Subject: [ruby-core:29399] Re: [Feature #2152] Split functionality of Float#inspect and Float#to_s > As I stated in [ruby-core:27631], I don't object about having two > string representation, one "human readable" and the other "more > verbose". �Even though I am not fully against, it doesn't mean, I > enjoy having two representation. �Float is float is float. �We should > know about error when you treat with float, shouldn't we? Agreed that we should (and 1.9.1 does not). For me, I think having two might be useful. Most people who write simple scripts, like print 2.1-0.9 probably want to output a humanized version by default, or at least have one available. Similarly for "float #{f}" et al. Somebody debugging code would want to be able to easily look closer, which 1.9.2 currently provides: >> a = 1.1 - 0.9 0.20000000000000007 >> b - 0.2 0.2 >> a == b => false > Anyway, I feel like we still have two points: > > (1) We've got consensus which method to behave which so far. �Since > � �#inspect is a method for "human readable" string representation, > � �I think it is more suitable to get "human readable" float > � �representation. �Others want to #to_s to be "human readable" to > � �ease "Float #{f}". From my perspective, to inspect means a "closer inspection" (i.e. more verbose output than to_s [1]). (Also, changing inspect instead of to_s would keep better backward compatibility, which might help people not get mad.) > (2) Besides that, I am not sure whether the old behavior is the best > � �way to generate "human readable" representation. Agreed. I do like the option Benoit proposed: (add a parameter, like f.to_s(2)) Then users are forced to realize that they are rounding, there is nothing implicit. This would be my preference (current behavior, but add parameter to to_s) Another option might be to use "%g" instead of "%.15g" ex: >> "%#.15g" % (1.4 - 0.1 - 1.2) => "0.0999999999999999" # current way for 1.9.1 > "%#g" % (1.4 - 0.1 - 1.2) => "0.100000" Anybody know why that 15 is in there? Much thanks. -roger [1] http://www.google.com/dictionary?aq=f&langpair=en%7Cen&hl=en&q=inspect