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
