R
rpardee
Hey All,
Looking at the google groups archive for this group, it seems that
there's no built-in way to round a float to a particular number of
decimal points. I thought I'd use that as an occasion to try my hand
at extending a built-in class, and wrote this:
class Float
def round(places)
num = ("1" + "0"*places.to_i).to_f
(self*num).round/num
end
end
But when I say:
p = 22.0/7
puts p.round(3).to_s
Ruby comes back with:
C:/Documents and Settings/pardre1/Desktop/DelMe.rb:4:in `round': wrong
number of arguments (0 for 1) (ArgumentError)
from C:/Documents and Settings/pardre1/Desktop/DelMe.rb:4:in `round'
from C:/Documents and Settings/pardre1/Desktop/DelMe.rb:9
What am I doing wrong?
Thanks!
-Roy
Looking at the google groups archive for this group, it seems that
there's no built-in way to round a float to a particular number of
decimal points. I thought I'd use that as an occasion to try my hand
at extending a built-in class, and wrote this:
class Float
def round(places)
num = ("1" + "0"*places.to_i).to_f
(self*num).round/num
end
end
But when I say:
p = 22.0/7
puts p.round(3).to_s
Ruby comes back with:
C:/Documents and Settings/pardre1/Desktop/DelMe.rb:4:in `round': wrong
number of arguments (0 for 1) (ArgumentError)
from C:/Documents and Settings/pardre1/Desktop/DelMe.rb:4:in `round'
from C:/Documents and Settings/pardre1/Desktop/DelMe.rb:9
What am I doing wrong?
Thanks!
-Roy