Your latter example seems quite nice.
Especially if it would accept unabbreviated forms such as this:

0.9.to_s(precision: 4, width: 6) #=> " 9.000"

- brent



Nobuyoshi Nakada-2 wrote:
> 
> Hi,
> 
> At Sat, 11 Apr 2009 15:17:24 +0900,
> Roger Pack wrote in [ruby-core:23179]:
>> Is this satisfactory, or would anyone still prefer Float#to_s
>> => rounded, Float#inspect => non rounded (i.e. 0.9.inspect =>
>> "0.8999999999")?  Just wondering since I brought up this mess
>> :)
> 
> I had another thought, Float#to_s could take an optional
> argument to specify the precision or the format.
> 
> e.g.:
> 
>   0.9.to_s(3)   #=> "0.900"
>   0.9.to_s("e") #=> "9.000000e-01"
>   0.9.to_s(prec: 4, width: 6) #=> " 9.000"
> 
> -- 
> Nobu Nakada
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-ruby-core%3A23075---Bug--1336--Change-in-string-representation-of-Floats-tp22798535p23004340.html
Sent from the ruby-core mailing list archive at Nabble.com.