admin管理员组

文章数量:1415698

Let's say we have these 2 values

1.230

That means in Italy one thousand and 230, if an American had to write that, would write

1,230

Currently using:

myValue.toLocaleString('it');

For US we should be using myValue.toLocaleString('en-US');

How would we detect the correct number format we should be displaying?

Let's say we have these 2 values

1.230

That means in Italy one thousand and 230, if an American had to write that, would write

1,230

Currently using:

myValue.toLocaleString('it');

For US we should be using myValue.toLocaleString('en-US');

How would we detect the correct number format we should be displaying?

Share Improve this question asked May 9, 2020 at 9:12 rob.mrob.m 10.6k21 gold badges88 silver badges175 bronze badges 1
  • Related: Javascript toFixed localized?. – Sebastian Simon Commented Jan 19, 2023 at 0:51
Add a ment  | 

2 Answers 2

Reset to default 8

Do you want something like that?

myValue.toLocaleString(navigator.language)

You can use Intl.NumberFormat as

var number = 3500;

console.log(new Intl.NumberFormat().format(number));

本文标签: javascriptHow to get numbers format based on user locationStack Overflow