Formats the value of a number to the specified precision.

Syntax

JSV_numberFormat(expN, expP)

Prototype

n/a

Returns

The numberFormat function returns the string representation of a number formatted to the specified precision.

Parameters

The numberFormat function uses the following arguments.

Argument Description
expN The number that is to be formatted.
expP The precision to which the formatting should occur.

Remarks

This function is similar to the round function, but pads the rounded number with the appropriate number of zeros.

Dependencies

n/a

Example

The following lines of code

var f = 1.0/5.0;
document.write( "The number " + f + 
    " can be formatted to 2 decimal places and be displayed as " + 
    JSV_numberFormat(f,2) );
document.write( "The number " + f + 
    " can be formatted to 4 decimal places and be displayed as " + 
    JSV_numberFormat(f,4) );

produce