Latest

recent

JavaScript toPrecision() Method

Definition and Usage

The toPrecision() method converts a number into a number with the specified number of digits.

Syntax

NumberObject.toPrecision(num)

Parameter Description
num Required. Specifies the number of digits the for the value


Example

In this example we will change number of digits for a number:

Show 10.000 with four digits:
<script type="text/javascript">
var num = new Number(10.000);
document.write (num.toPrecision(4));
</script>

The output of the code above will be:

Show 10.000 with four digits:
10.00
JavaScript toPrecision() Method Reviewed by 1000sourcecodes on 22:55 Rating: 5
Powered by Blogger.