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" >
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 >
< 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
Last Updated :
03 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...