Latest

recent

JavaScript toFixed() Method

Definition and Usage

The toFixed() method rounds the Number to the specified number of decimal places.

Syntax

NumberObject.toFixed(num)

Parameter Description
num Required. Specifies the number of decimals to use


Example

In this example we will round a number to only use one decimal:

Show the number 13.37 with one decimal:
<script type="text/javascript">
var num = new Number(13.37);
document.write (num.toFixed(1));
</script>

The output of the code above will be:

Show the number 13.37 with one decimal:
13.4
JavaScript toFixed() Method Reviewed by 1000sourcecodes on 22:57 Rating: 5
Powered by Blogger.