DEV Community

Formatting Numbers in JavaScript with Intl.NumberFormat

Orim Dominic Adah on January 13, 2020

According to the documentation on MDN, The Intl.NumberFormat object is a constructor for objects that enable language-sensitive number formatti...
Collapse
 
tttony profile image
Tony

I needed to format a number and I just discovered that in spanish if the number 12345.67 it will print 12.345,67 cool but if the number is 1234.56 it will print 1234,56 not cool, it should be: 1.234,56, still looking a way to do it without regex

Collapse
 
orimdominic profile image
Orim Dominic Adah

Hello Tony. I am replying late, I guess, but I should. haha
What language locale are you converting from, and to?

Collapse
 
tttony profile image
Tony

No problem, I read this: stackoverflow.com/questions/589913..., so it's an expected behaviour

Collapse
 
acekyd profile image
Adewale Abati

Thanks for sharing.

Collapse
 
acekyd profile image
Adewale Abati

I'm curious though. How did you find the configuration options? I spent a while searching for them before coming across your post. It doesn't seem to be on the Documentation page. Would appreciate if you could share. Thanks.

Collapse
 
orimdominic profile image
Orim Dominic Adah

What! Boss! You read my post! Arrrgggh! You made my daaaaaay.. or night..

You're one of the Nigerian devs I look up to. Feels good to see your comment here.

Now for the answer to your question.. Drum roll..

developer.mozilla.org/en-US/docs/W...

I got there by clicking the constructor link in the compatibility table

Thanks again. This means much to me.. That you read and commented on my article

Thread Thread
 
acekyd profile image
Adewale Abati

Thank you for the kind words... Keep up the good work and thanks for sharing.

Collapse
 
aalabi profile image
aalabi

u are right the doc page on MDN has nothing on the parameter for the constructor.

Thread Thread
 
orimdominic profile image
Orim Dominic Adah

Apologies.
Here you are => developer.mozilla.org/en-US/docs/W...

Collapse
 
jankapunkt profile image
Jan Küster

Thank you for pointing me to this. I read a lot of MDN documentation but yet I did not stumbled over this one. Powerful tool indeed.

Collapse
 
orimdominic profile image
Orim Dominic Adah

Whoa! Thanks! This feedback really means a lot! Blessings!

Collapse
 
aalabi profile image
aalabi

parameter to be passed into the constructor was not explained in MDN doc or maybe I was looking at the wrong place in the doc.

Collapse
 
harshitjoshi9152 profile image
Harshit

is there a way to convert numbers like 70,678 to a format like this 70.6k ?

Collapse
 
stipro profile image
Franko

good day, I have the format in an input, how could I reverse it or put it back to its original format, thanks