From: Brent Roman Date: 2009-04-13T10:54:46+09:00 Subject: [ruby-core:23187] Re: [Bug #1336] Change in string representation of Floats Perhaps I'm not understanding the question. Consider: s = "string" s.inspect ==> "string" #this will round-trip s.to_s ==> string #this lacks the required delimiters s = :symbol s.inspect ==> :symbol #similarly... s.to_s ==> symbol #but this lacks delimiters and is abiguous a = [1,2,3] #again... a.inspect ==> [1, 2, 3] a.to_s ==> 123 #this is pretty useless h = [:foo=>:bar, :bar=>:foo] #and, finally... a.inspect ==> {:foo=>:bar, :bar=>:foo} a.to_s ==> foobarbarfoo #as is this. In all the above examples, the #inspect method outputs delimiters necessary for Ruby's parser to recreate the data object, while the #to_s method omits delimiters to produce terser, albeit sometimes ambiguous, output. Admittedly, to_s doesn't work very well on collections, but, it will convert any basic type to a short, human readable string free of extraneous punctuation. Float#to_s should do the same for consistency' sake. As a practical matter, changing Float#to_s at this point will cause many no longer maintained Ruby scripts to output confusing long trains of digits after the decimal. And, consider the bugs that will emerge when data base queries on ranges of values like 0.1 to 0.9, if the string representations actually passed (from Ruby via Float.to_s) into the data base engine (which for all we know is using decimal floats) are in fact 0.10000000000000001 to 0.90000000000000002 - brent Yukihiro Matsumoto wrote: > > Hi, > > In message "Re: [ruby-core:23181] Re: [Bug #1336] Change in string > representation of Floats" > on Sun, 12 Apr 2009 03:53:12 +0900, Brent Roman > writes: > > |I'd prefer that Float#to_s => rounded, Float#inspect => non rounded > |(i.e. 0.9.inspect => "0.8999999999") > > I see several people who prefer that way. Could you elaborate the > reason behind the preference? Considering being to_s for mere string > representation, and inspect being human readable string > representation, I thought other way around. > > matz. > > > -- View this message in context: http://www.nabble.com/-ruby-core%3A23075---Bug--1336--Change-in-string-representation-of-Floats-tp22798535p23016776.html Sent from the ruby-core mailing list archive at Nabble.com.