Thursday, September 4, 2025
HomeLanguagesJavascriptFabric.js toFixed() Method

Fabric.js toFixed() Method

The toFixed() method in Fabric.js is used to convert the specified fraction number into a rounded fixed number.

Syntax:

toFixed(number, fractionDigits)

Parameters: This method accepts two parameters as mentioned above and described below:

  • number: This parameter holds the fraction number.
  • fractionDigits: This parameter holds the number of fraction digits to leave after the decimal point of specified fraction number.

Return Value: This method returns the converted fixed number.

Example 1:

Javascript




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
        // Calling toFixed() function over
        // some specified fraction number
        console.log(fabric.util.toFixed(1234.567));
        console.log(fabric.util.toFixed(1234.567, 1));
        console.log(fabric.util.toFixed(1234.567, 2));
        console.log(fabric.util.toFixed(1234.567, 3));
        console.log(fabric.util.toFixed(1234.567, 4));
    </script>
</body>
 
</html>


Output:

1235
1234.6
1234.57
1234.567
1234.567

Example 2:

HTML




<!DOCTYPE html>
<html>
 
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
     
        // Specifying some fraction numbers
        var number1 = 0;
        var number2 = 123;
        var number3 = 0.789;
 
        // Specifying some fractionDigits
        var fractionDigits1 = 1;
        var fractionDigits2 = 2;
 
        // Calling toFixed() function over
        // the above specified fraction numbers
        // and fractionDigits
        console.log(fabric.util.toFixed(number1));
        console.log(fabric.util.toFixed(number2));
        console.log(fabric.util.toFixed(number2,
            fractionDigits1));
        console.log(fabric.util.toFixed(number3,
            fractionDigits1));
        console.log(fabric.util.toFixed(number3,
            fractionDigits2));
    </script>
</body>
 
</html>


Output:

0
123
123
0.8
0.79
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6628 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS