![]() |
VOOZH | about |
The toFixed() function in TypeScript formats a number using fixed-point notation, specifying the number of digits after the decimal point. It returns a string representation of the number, ensuring precise control over its decimal places for consistent numerical formatting.
number.toFixed( [digits] );
Parameters:
Return Value: The toFixed() method returns a string representation of the number that does not use exponential notation and has the specified number of digits after the decimal place.
Below examples illustrates the working of toFixed() function in TypeScript :
In this example, we demonstrate how to use the toFixed() function to format a number with and without specifying the number of digits after the decimal point.
Output:
num.toFixed() is 358
num.toFixed(2) is 358.42
Here, we show how to format a number with different numbers of digits after the decimal point using the toFixed() function.
Output:
num1.toFixed() is 526
num1.toFixed(4) is 526.1230
num1.toFixed(7) is 526.1230000