When handling percentage calculations:
Simple 99/100…
Will I always have to do 99.to_f/100.to_f in order to receive 0.99? Or
is there a simpler way of performing this task in ruby…
I notice that there doesn’t appear to be a round method with decimal
places (or perhaps I can’t find one) so I found this one which appears
to work:
class Float
def round_to(x)
(self * 10x).round.to_f / 10x
end
def ceil_to(x)
(self * 10x).ceil.to_f / 10x
end
def floor_to(x)
(self * 10x).floor.to_f / 10x
end
end
The question I have is can I expand upon divisor behavior and create
something that changes the way ruby behaves with integers/floats on a
more permanent basis?
I only ask because I’m working with standard deviation and some advanced
mathematics that revolve around calculating variance. I just don’t want
to experience any gotchas halfway down my project.
Lastly, is there a good core site that houses all of the API for ruby
math functions or refined methods that deal with variance?
Many thanks.