JavaScript Basics
JavaScript Objects
JavaScript Advanced
JS Useful References
JS Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Javascript Number - toFixed()
Description:
This method formats a number with a specific number of digits to the right of the decimal.
Syntax:
number.toFixed( [digits] )
|
Here is the detail of parameters:
Return Value:
A string representation of number that does not use exponential notation and has exactly digits digits after the decimal place.
Example:
<html>
<head>
<title>JavaScript toFixed() Method</title>
</head>
<body>
<script type="text/javascript">
var num=177.1234;
document.write("num.toFixed() is : " + num.toFixed());
document.write("<br />");
document.write("num.toFixed(6) is : " + num.toFixed(6));
document.write("<br />");
document.write("num.toFixed(1) is : " + num.toFixed(1));
document.write("<br />");
document.write("(1.23e+20).toFixed(2) is:" +
(1.23e+20).toFixed(2));
document.write("<br />");
document.write("(1.23e-10).toFixed(2) is : " +
(1.23e-10).toFixed(2));
</script>
</body>
</html>
|
This will produce following result:
num.toFixed() is : 177
num.toFixed(6) is : 177.123400
num.toFixed(1) is : 177.1
(1.23e+20).toFixed(2) is:123000000000000000000.00
(1.23e-10).toFixed(2) is : 0.00
|
To understand it in better way you can Try it yourself.
|
|
|