Round Half To Even With Javascript

Updated: v0.2.1

(special thanks to: Donatas v0.2.0 (http://happycode.info)

The following script provides an easy way to perform unbiased rounding, convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, or bankers' rounding using Javascript.

Examples

var numToRound = 10.005;
numToRound.rhte(0.01);
result: 10.00

var numToRound = 10.0015;
numToRound.rhte(0.001);
result: 10.002

var numToRound = 10.00500000001;
numToRound.rhte(0.01);
result: 10.01

var numToRound = 1005001;
numToRound.rhte(10000);
result: 1010000

 

<script> <html> Result:

Run

Comments are closed.