Truncates the value to the specified number of places. This function does not round the value.

Syntax

JSV_truncate(expN, expD)

Prototype

n/a

Returns

The truncate function returns the value of a number truncated to the specified number of places.

Parameters

The truncate function uses the following arguments.

Argument Description
expN The number to be truncated.
expD The specified number of places to truncate to.

Remarks

For more information on this topic, see the article Significant Digits by Aaron Weiss.

Dependencies

n/a

Example

The following lines of code

var f = 1.0/3.0;
document.write( "The number " + f + 
    " can be truncated to 3 decimal places and be displayed as " + 
    JSV_truncate(f,3) );
var f = 1.0/8.0;
document.write( "The number " + f + 
    " can be truncated to 2 decimal places and be displayed as " + 
    JSV_truncate(f,2) );

produce