Skip to content
Advertisements

Number.toFixed()

Why toFixed ?

The JavaScritpt toFixed () method is used to format a number using a fixed point representation. If the decimal number we want is higher, blank values can be added to create the desired decimal length.

Syntax:

number.toFixed( value )

  • value ( optional ): The number of digits after the decimal point. Default is 0.

JavaScript toFixed Examples

Example 1

In the following example, the num variable is assigned the number 2.4363. Then I set the value as myFix, with the help of the variable toFixed (). Then I return the value.

        let num = 2.4363;
        let myFix = num.toFixed(2);
        console.log(myFix)

output:

2.44


Example 2

        let num1 = 4.3621;
        let num2 = 9.9851;
        let num3 = 54.399999;
        let num4 = 1.46e+20;
        let num5 = -3.23299;

        console.log(num1.toFixed(3));
        console.log(num2.toFixed(2));
        console.log(num3.toFixed(5));
        console.log(num4.toFixed(4));
        console.log(num5.toFixed(3));

output:

4.362
9.99

146000000000000000000.0000
-3.233


Browser Support

Chromeyes
Edgeyes
Firefox1
Internet Exploreryes
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

3 Comments »

  1. Simply desire tо say your aгticle is as amazing. The clearness іn your post is simply greаt and that
    i could think you are knowledgeable in this subject. Ꮃell
    with your permissіon let me tօ seize yօur feed to stay up to date witһ imminent post.
    Thanks a million and please carry on the enjoyable work.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: