TypeScript | toFixed() Function
The toFixed() function in TypeScript is used to format a number using fixed-point notation. It can be used to format a number with a specific number of digits to the right of the decimal.
number.toFixed( [digits] );
Parameters: This function accepts a parameter value- digits– The number of digits to appear after the decimal point.
Return Value: The toFixed() method in TypeScript returns a string representation of number that does not use exponential notation and has the exact number of digits after the decimal place.
Below examples illustrates the working of toFixed() function in TypeScript :
num = 358.429
"num.toFixed() is "
"num.toFixed(2) is "
num.toFixed() is 358
num.toFixed(2) is 358.42
num1 = 526.123
"num1.toFixed() is "
"num1.toFixed(4) is "
"num1.toFixed(7) is "
num1.toFixed() is 526
num1.toFixed(4) is 526.1230
num1.toFixed(7) is 526.1230000
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!