Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relation between Number.prototype.toLocaleString() and Intl.NumberFormat.prototype.format?

We are trying to use localization support in our application and looking at the toLocaleString(). We also had a look at Intl.NumberFormat and its format method.

Do they have any relation? Which one is better to use?

like image 672
TypeScripter Avatar asked Sep 28 '16 15:09

TypeScripter


1 Answers

From MDN docs for Number.prototype.toLocaleString():

Performance:

When formatting large numbers of numbers, it is better to create a NumberFormat object and use the function provided by its NumberFormat.format property.

In most cases you can use Number.prototype.toLocaleString(). It's simpler to use, because it allows you to format a number using one function call. Intl.NumberFormat is useful only when you want to format a large amount of numbers.

like image 92
Michał Perłakowski Avatar answered Oct 26 '22 18:10

Michał Perłakowski