K
Keith Fahlgren
Hi,
I need to truncate some Floats and found this:
http://www.approximity.com/cgi-bin/blogtariAgile/index.rb/+Forth/RetroWeb.rdoc
It suggests:
class Float
def truncate(sd=2)
scale=(10**sd).to_f
(self * scale).to_i / scale
end
end
a=0.255
a.truncate(2) #-> 0.25
Is there a better way to do the above? I'm sort of surprised that there
isn't a builtin, but perhaps I'm not looking in the right place.
Thanks,
Keith
I need to truncate some Floats and found this:
http://www.approximity.com/cgi-bin/blogtariAgile/index.rb/+Forth/RetroWeb.rdoc
It suggests:
class Float
def truncate(sd=2)
scale=(10**sd).to_f
(self * scale).to_i / scale
end
end
a=0.255
a.truncate(2) #-> 0.25
Is there a better way to do the above? I'm sort of surprised that there
isn't a builtin, but perhaps I'm not looking in the right place.
Thanks,
Keith