Revision: 2388
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 7, 2007 09:48 by vanne
Initial Code
class Float # USAGE : 123123123.123131.decimal # => 123123123.12 # OR 123123123.123131.decimal 4 # => 123123123.1231 # Defaults to a scale of 2 def decimal(prec=2) number = self.to_s.split(".")[0] scale = self.to_s.split(".")[1][0..(prec-1)] "#{number}.#{scale}".to_f end end
Initial URL
Initial Description
Extend any float object to allow for decimal conversion
Initial Title
decimal method for float objects
Initial Tags
ruby
Initial Language
Ruby