
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Number - toFixed()
Description
This method formats a number with a specific number of digits to the right of the decimal.
Syntax
Its syntax is as follows −
number.toFixed( [digits] )
Parameter Details
digits − The number of digits to appear after the decimal point.
Return Value
A string representation of number that does not use exponential notation and has the exact number of digits after the decimal place.
Example
Try the following 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>
Output
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
javascript_number_object.htm
Advertisements