Rounds the value of a number to the specified precision.
JSV_round(expN, expP)
n/a
The round function returns the value of a number rounded to the specified precision.
The round function uses the following arguments.
Argument | Description |
expN | The number that is to be rounded. |
expP | The precision to which the rounding should occur. |
This function is different than the round
method of the
Math
object which returns the value of a number rounded to the nearest integer. We are interested in overcoming
JavaScript's limitations with decimal precision.
For more information on this topic, see the article Significant Digits by Aaron Weiss.
n/a
The following lines of code
var f = 1.0/3.0;
document.write( "The number " + f +
" can be rounded to 3 decimal places and be displayed as " +
JSV_round(f,3) );
var f = 1.0/8.0;
document.write( "The number " + f +
" can be rounded to 2 decimal places and be displayed as " +
JSV_round(f,2) );
produce
Copyright © 1998-2000 Roaring Fork Software. All rights reserved.