for example:
i = 0.33533333333 round up to "0.34"
thanks.
for example:
i = 0.33533333333 round up to "0.34"
thanks.
david wrote:
i = 0.33533333333 round up to "0.34"
sprintf("%2.2f", i)
Hmm and if you want a float then:
eval(sprintf("%2.2f",i))
Also, if you want to just round:
i.round #=> will give 0 for 0.33335
And If you don't really like eval then, you would have to get your hand
dirty and :
class Float
def round2f places
sprintf("%.#{places}f",self).to_f
end
end
hi,
what about this…
irb(main):035:0> i = 0.33533333333
=> 0.33533333333
irb(main):036:0> Integer(i*100)/100.0
=> 0.33
in case .34 is required
can do
irb(main):040:0> Integer((i*100).ceil)
=> 34
regards
gaurav
Hi, I've got it. thanks, everyone.