number-extended
v0.0.2
Published
Number utilities
Downloads
1
Readme
number-extended
number-extended
is a Javascript library that can contains different number utilities.
number-extended
can be used as a monad library that be be incorporated into extended
or used standalone.
var num = require("number-extended");
num.round(10.000009, 5); //10.00001
Or
var myextended = require("extended")
.register(require("number-extended"));
num.round(10.000009, 5); //10.00001
Installation
npm install number-extended
Or download the source (minified)
Usage
round
Rounds a number to the specified places.
//as a function
num.round(10.000009, 2); //10
num.round(10.000009, 5); //10.00001
num.round(10.0009, 3); //10.001
num.round(10.0009, 2); //10
num.round(10.0009, 3); //10.001
//as a monad
num(10.000009).round(2).value(); //10
num(10.000009).round(5).value(); //10.00001
num(10.0009).round(3).value(); //10.001
num(10.0009).round(2).value(); //10
num(10.0009).round(3).value(); //10.001
You can also provide an optional increment argument which rounds in the number in the specified increment.
console.log(num.round(10.01, 2, 0.02)); //10.02
console.log(num.round(10.02, 2, 0.02)); //10.02
console.log(num.round(10.03, 2, 0.02)); //10.04
console.log(num.round(10.04, 2, 0.02)); //10.04
console.log(num.round(10.05, 2, 0.02)); //10.06
console.log(num.round(10.06, 2, 0.02)); //10.06
console.log(num.round(10.07, 2, 0.02)); //10.08
console.log(num.round(10.08, 2, 0.02)); //10.08
console.log(num.round(10.09, 2, 0.02)); //10.01
roundCeil
Rounds a number to the specified places, rounding up.
//as a function
num.roundCeil(10.000001, 2); //10.01
num.roundCeil(10.000002, 5); //10.00001
num.roundCeil(10.0003, 3); //10.001
num.roundCeil(10.0004, 2); //10.01
num.roundCeil(10.0005, 3); //10.001
num.roundCeil(10.0002, 2); //10.0
//as a monad
num(10.000001).roundCeil(2); //10.01
num(10.000002).roundCeil(5); //10.00001
num(10.0003).roundCeil(3); //10.001
num(10.0004).roundCeil(2); //10.01
num(10.0005).roundCeil(3); //10.001
num(10.0002).roundCeil(2); //10.0