Reputation: 2153
My JavaScript toLocaleString()
is doing something strange here. If I have a number less than 1000, it will give dot as decimal delimiter, but if I have a number more than 1000, it will give me comma as decimal delimiter.
My locale setting uses dot as thousand delimiter and comma as decimal delimiter.
This is how I use the code:
sellingPrice.toLocaleString(undefined, { minimumFractionDigits: 2 }
If sellingPrice is 700
, it will give me 700.00
If sellingPrice is 7000
, it will give me 7.000,00
But the result is the same
Why is this happening?
Upvotes: 2
Views: 1825
Reputation: 1
var sellingPrice=700;sellingPrice.toLocaleString('en-us', { minimumFractionDigits: 2 });
will give you the result 700.00
and
var sellingPrice=7000;sellingPrice.toLocaleString('en-us', { minimumFractionDigits: 2 });
will give you the result 7,000.00
Upvotes: 0
Reputation: 2153
I just found out that javascript is following the browser locale.
In my case I use chrome. I have to change the language to my language (Indonesia) to achieve my goal, which is a bit disappointing. I want my browser language to be English.
I cannot use "en" or "de" because I want the code to be dynamic and follows the user locale.
Upvotes: 1