JavaScript Number.toFixed() Method

You are Here:

JavaScript Number.toFixed() Method

The Number.toFixed() method returns a string representing the given number using fixed-point notation.

Note: The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.

Note: If a number is greater or equal to 1e+21, this method simply calls Number.prototype.toString() and returns a string in exponential notation.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var numObj = 12.98765; var result = numObj.toFixed(2); document.write(result); </script> </body> </html>

Syntax

Number.toFixed(x)

Parameter Values

ValueTypeExplanation
xoptionalThe number of digits to appear after the decimal point.
A range is between 0 and 20.
If omitted, the default value is '0'.

Return Value

ValueExplanation
stringReturns a string representing the given number using fixed-point notation.

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var numObj = 12.98765; var result1 = numObj.toFixed(2); var result2 = numObj.toFixed(); document.write(result1 +"<br>"); document.write(result2); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author