Rounding off floating point numbers in Ruby
Problem:
If you want to round a floating point number off to two decimals, there is no standard method in Ruby that does it for you.
Solution:
The general solution is
(f * 10**d).round.to_f / 10**d
where f is the floating number and d is the number of decimals.
See my code sample for adding this functionality to the Float class.
Although [...]