Monday, November 18, 2024
Google search engine
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

Recent Comments