Navigate back to the homepage

How to convert number to decimal in typescript?

January 29th, 2022 · 1 min read
keep affilitate

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.

1let num : number = 100;
2num.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.

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

it’s also rounding decimal places automatically.

Thanks for reading…

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to convert string array to number array in typescript?

TypeScript, convert string arrays to number arrays example.

January 28th, 2022 · 1 min read

how to remove curly braces from string in javascript?

Javascript, delete curly braces from string example.

January 24th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]