From: Robert Klemme Date: 2007-12-01T19:25:01+09:00 Subject: Re: Float Question On 01.12.2007 09:26, Armando Padilla wrote: > Hey Chris thanks for the feedback. Yea im using that but i was looking > for something built into the Float stack. Class != stack. > Something along the lines of > Float.new(). Basically something > without the need to use sprintf. I fail to see where the issue with using (s)printf is. Anyway, if you do not like the syntax of sprintf you can as well do this: irb(main):001:0> f=1.0/3 => 0.333333333333333 irb(main):002:0> "%.2f" % f => "0.33" > Next release of Ruby request? lol Probably not. As others have demonstrated, you can easily do this in Ruby today. But it seems, few people know the star operator in printf format strings. You can do this: irb(main):021:0> module Precision irb(main):022:1> def format(decimals,total=0) irb(main):023:2> sprintf "%*.*f", total, decimals, self irb(main):024:2> end irb(main):025:1> end => nil irb(main):026:0> f=1.0/3 => 0.333333333333333 irb(main):027:0> f.format 3 => "0.333" irb(main):028:0> f.format 3,10 => " 0.333" Kind regards robert