Javascript format numbers

linkaiyi
Follow

Format numbers in Javascript

.toLocaleString(‘en’) is one simple way to get thousand separator and round

(1234567.89).toLocaleString('en')              // for numeric input
parseFloat("1234567.89").toLocaleString('en')  // for string input

or use toFixed(n) to round the number to n precision
If the value is a text type:

parseFloat("123.456").toFixed(2);

If the value is a number:

var numb = 123.23454;
numb = numb.toFixed(2);
Object has 0 attachments

Was this article helpful?

This article is viewed 22 times!

0 Comments

Leave a Comment

Support