Open In App

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:

Return Value: This method returns the converted fixed number.



Example 1:




<!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:




<!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

Article Tags :