roundn
Round values to the nearest multiple of 10^n.
Installation
$ npm install compute-roundn
For use in the browser, use browserify.
Usage
To use the module,
var roundn = ;
roundn( x, n )
Rounds values to the nearest multiple of 10^n
. x
may be either a numeric array
or a single numeric value. n
must be an integer
specifying the multiple of 10^n
to which the value(s) should be rounded.
var val = ;// returns 2.46
Examples
// Round a value to 2 decimal places:console;// returns 3.14// If `n=0`, then `roundn()` behaves like `Math.round()`:console;// returns 3console;// returns 3// Round a value to the nearest thousand:console;// returns 12000// Round each array value to 2 decimal places...var data = 5 ;for var i = 0; i < datalength; i++data i = MathPI;console;// returns [ 3.14, 3.14, 3.14, 3.14, 3.14 ]
To run the example code from the top-level application directory,
$ node ./examples/index.js
Notes
If provided an input array
, the array
is mutated. If mutation is undesired,
var data = MathPI MathPI MathPIcopy = data;;
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2014. Athan Reines.