JavaScript toFixed() Method
Complete Number Object Reference
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:
|
Try-It-Yourself Demos
toFixed()
How to use toFixed() to round a number.
Complete Number Object Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
|
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|