Is Intl.NumberFormat formatting correct for Poland?
Asked Answered
D

2

6

I have noticed that the formating of several countries (Poland, Russia, France and more) follows a strange behaviour. The format starts to apply on values with more that 4 digits. You can see it in the code below.

Unfortunately I haven't found any international standards for that and I have seen that in other programing languages the format for this countries starts from the 4th digit.

I am wondering if the Intl.NumberFormat follows the correct formatting standards.

const simpleFormat = new Intl.NumberFormat('pl-PL', {
  style: 'decimal'});
let short = simpleFormat.format(1234);
let long = simpleFormat.format(12345);

console.log(short);
console.log(long);

Expected output:

1 234

12 345

Ddene answered 8/2, 2021 at 14:11 Comment(2)
According to ECMA 402, "Localized decimal and grouping separators" are implementation-dependent. I'm seeing what you're seeing on Firefox 85.0, Arch Linux: 1234 and 12 345.Halinahalite
As a datapoint, Estonian uses similar logic where you don't insert a space for 4-digit numbers (1234), but you do for 5-digit ones (12 345). While I haven't traced down the official spec here, I wouldn't find it surprising if Polish did something similar.Nuthatch
A
3

in case anyone is still looking for it - Intl.NumberFormat has an option useGrouping and if it is set to true for pl then space separator is also inserted in the 4-digit number

Archduchess answered 1/3, 2023 at 8:7 Comment(2)
Unfortunately this won't do. I tried: new Intl.NumberFormat('pl-PL').format(1000, { useGrouping:true }); with no successFulbert
@Fulbert your code is wrong, use this way :console.log(new Intl.NumberFormat('pl-PL',{useGrouping:true}).format(54321));Plead
B
2

It works for me:

(1000).toLocaleString('pl-PL', {useGrouping: true})
// result: '1 000'

You can add:

(1000).toLocaleString('pl-PL', {useGrouping:true, minimumFractionDigits:2, maximumFractionDigits:2})
// result: '1 000,00'

test Snippet

let ValStr = (1000).toLocaleString( 'pl-PL'
                                   , { useGrouping           : true
                                     , minimumFractionDigits : 2
                                     , maximumFractionDigits : 2
                                   } );

console.log( ValStr );  // result: '1 000,00'
Borborygmus answered 11/1, 2024 at 3:56 Comment(3)
This does not work in Firefox, as far as I can tell.Anhwei
@Anhwei I added a sinppet and it works for me on Firefox (vers : 125.0.2)Plead
^Can confirm as wellCaputto

© 2022 - 2025 — McMap. All rights reserved.