roundit
javascript rounding library
A quick and simple rounding library, without resorting to string conversion, manipulation or other 3rd party maths routines.
Usage:
var round = ; console; console; console; console; console;
Rounding Options
nearest
Standard rounding to nearest number, >= 0.5 up, < 0.5 down.
round.nearest(value to round, decimal places)
1.5 to 0 decimal places => 2
1.4 to 0 decimal places => 1
ceil
Always round up to larger significant digit (toward positive infinity).
round.ceil(value to round, decimal places)
1.5 to 0 decimal places => 2
-1.5 to 0 decimal places => -1
floor
Always round up to smaller significant digit (toward negative infinity).
round.floor(value to round, decimal places)
1.5 to 0 decimal places => 1
-1.5 to 0 decimal places => -2
fix
Always round towards zero.
round.fix(value to round, decimal places)
1.5 to 0 decimal places => 1
-1.5 to 0 decimal places => -1
infinite
Always round away from zero (toward +-infinity).
round.infinite(value to round, decimal places)
1.5 to 0 decimal places => 2
-1.5 to 0 decimal places => -2