Skip to content

compute roundn

kgryte edited this page May 12, 2015 · 1 revision

Rounds values to the nearest multiple of 10^n. x may be either a single numeric value or an array of values. n must be an integer.

compute.roundn( Math.PI, -2 );
// returns 3.14

var x = compute.roundn( 111, 2 );
// returns 100

var data = [ 2.342, 4.943, 2.234, 7.992, 3.142 ];

compute.roundn( data, -2 );
// returns [...] where each value is rounded to nearest hundredth

Note: if provided an array, the array is mutated.

Clone this wiki locally