# Format numbers depending on selected locale

**URL:** https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418
**Category:** Feature
**Tags:** translation, polls
**Created:** [June 24, 2015, 7:22pm UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418 "2015-06-24T19:22:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [June 24, 2015, 7:22pm UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418/1 "2015-06-24T19:22:52Z")

</div>

Continuing the discussion from [Is there a way to translate numbers e.g. "1.3K" in the "Views" column?](https://meta.discourse.org/t/is-there-a-way-to-translate-numbers-e-g-1-3k-in-the-views-column/30374/10):

Looking at the code I noticed that numbers aren’t formatted using the locale configured by the user or administrator.  
This can be seen at the reply and view counts. On a German locale it looks like this:

![](https://global.discourse-cdn.com/meta/original/3X/a/a/aa569acf9d1f1183eb58d253242f65e9d9f78867.png)

But it should look like this:  
 ![](https://global.discourse-cdn.com/meta/original/3X/4/b/4b8f408e79f31673da83a9771e49bb7a0952a148.png)

In German we use a comma as decimal separator. And of course, as @downey [already mentioned](https://meta.discourse.org/t/is-there-a-way-to-translate-numbers-e-g-1-3k-in-the-views-column/30374/2) the “K” should be a lowercase “k”. 😉

The missing localization of numbers can also be seen in the poll plugin. The average rating uses the English decimal separator…  
 ![](https://global.discourse-cdn.com/meta/original/3X/c/5/c5045537b3601835b16ebef86ca4560172be45d0.png)

Could we use a library like [FormatJS](http://formatjs.io/) or [Numeral.js](http://numeraljs.com/) in order to format numbers? Looks like not all major browsers support [Intl.NumberFormat](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) yet. ☹

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 24, 2015, 11:07pm UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418/2 "2015-06-24T23:07:24Z")

</div>

hmmm why do we need to pull a whole new library in for this, we already have … `/lib/locale/en.js` etch… why not just add another method there.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [June 25, 2015, 8:15am UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418/3 "2015-06-25T08:15:45Z")

</div>

Yeah, I guess adding another library isn’t the best option. In an ideal world we could just use `Intl.NumberFormat`, but of course Safari and all those mobile browsers lack support for it. 😠

But [FormatJS](http://formatjs.io/) looks promising. It’s using a [polyfill for Intl](https://github.com/andyearnshaw/Intl.js), integrates well with Ember ~~and I’m quite sure it would be possible to replace moment.js with it too~~. (Ok, moment.js is currently used for parsing and calculating dates, so replacing it is probably not an option.)

Anyway, we need some kind of solution for this. If it’s just a “simple” function in those `lib/locale` scripts, that’s fine with me too.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [June 25, 2015, 9:59am UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418/4 "2015-06-25T09:59:38Z")

</div>

Looks like there’s already some code that could handle localized number formats. It’s just not used…

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/locales/i18n.js#L353-L358](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/locales/i18n.js#L353-L358)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [September 23, 2015, 1:13pm UTC](https://meta.discourse.org/t/format-numbers-depending-on-selected-locale/30418/5 "2015-09-23T13:13:34Z")

</div>


