Hello Friends 👋,

Welcome To Infinitbility! ❤️

Many times, we have to convert numbers to decimals to show value more attractive and informative to the user.

TypeScript have toFixed() method to convert number spcfied decimal places.

For example

If we pass 2 in toFixed() method for 100 it will return 100.00 in string.

let num : number = 100;
num.toFixed(2); // '100.00'

The toFixed() method also helps to define decimal places like if we have 23.3476354 and you want to only two decimal places then also you can use it.

let num : number = 23.3476354;
num.toFixed(2); // 23.35

it’s also rounding decimal places automatically.

Thanks for reading…