A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-number-tofixed-method/ below:

JavaScript Number toFixed() Method - GeeksforGeeks

JavaScript Number toFixed() Method

Last Updated : 09 Jan, 2024

The toFixed() method converts a number to a string. The toFixed() method rounds the string to a specified number of decimals.

Notes:
Syntax:
number.toFixed( value );
Parameters: Return Value:

It returns a number in the string representation. The number has the exact number of digits after the decimal place as mentioned in the toFixed() method. 

Example 1: Using toFixed() method with a parameter 1, displays decimal points to one digit.

JavaScript
let test=213.73145;
console.log(test.toFixed(1));        

Example 2: Using toFixed() method without any parameter, If there is no parameter specified in the toFixed() method then it doesn't display any digits after the decimal place. 

JavaScript
let test=213.73145;
console.log(test.toFixed());        

Example 3: Using toFixed() method with a parameter, If there is a parameter specified in the toFixed() method will return a number represented as a string which will have exactly that number of digits after the decimal place. 

JavaScript
let test=213.73145;
console.log(test.toFixed(3));        

Example 4: Using toFixed() method where the number is in exponential form. The toFixed() method can be used to convert an exponential number into a string representation with a specific number of digits after the decimal place. 

JavaScript
let test=2.13e+15;
console.log(test.toFixed(2));        

Output
2130000000000000.00
Supported Browsers:

We have a complete list of Javascript Number Objects methods, to check those please go through this Javascript Number Complete reference article.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4