4

I've updated my project to iOS 13 and I've realised that the price formatter I was using for formatting the prices has stopped working correctly.

The groupingSeparator, the symbol that groups the thousands, is missing for 4 digits numbers: from 1000 to 9999 when using a the Spanish locale es_ES.

Below there is a simple snipped to verify it. NumberFormatter seems to be working perfectly for en_US locale and for numbers higher than 9999 but whenever use es_ES locale and try to format a 4 digits number, the groupingSeparator (thousands separator) is missing, so instead of getting 1.000, I'm getting 1000.


let enFormatter = NumberFormatter()
enFormatter.locale = Locale(identifier: "en_US")
enFormatter.numberStyle = .decimal
enFormatter.string(from: 1000)
enFormatter.string(from: 9999)
enFormatter.string(from: 10000)
enFormatter.string(from: 100000)

let esFormatter = NumberFormatter()
esFormatter.locale = Locale(identifier: "es_ES")
esFormatter.numberStyle = .decimal
esFormatter.string(from: 1000)
esFormatter.string(from: 9999)
esFormatter.string(from: 10000)
esFormatter.string(from: 100000)

Just paste it into a playground and check the outputs.

Different outputs for en_US and es_ES NumberFormatter

Am I missing something?

So far I've reported the problem to Apple: FB7416623 https://feedbackassistant.apple.com/feedback/7416623 (not sure if the link works)

I'll keep this updated, but I would appreciate if anybody has more information about it.

5
  • Is it normal in Spain to show the grouping separator with just 4 digits?
    – rmaddy
    Commented Oct 29, 2019 at 18:20
  • 3
    Related: stackoverflow.com/questions/58544119/…
    – rmaddy
    Commented Oct 29, 2019 at 18:24
  • Yes, it is normal. Thanks a lot for the related link. It seems that it is related to more locale, not only es_ES Commented Oct 29, 2019 at 18:26
  • 2
    But see Rob’s comment stackoverflow.com/questions/58607986/… I am not convinced there’s a bug here. It seems to me that the earlier behavior was the bug.
    – matt
    Commented Oct 29, 2019 at 18:59
  • Thanks @matt, you were right, i've just checked it with the Royal Academy of the use of Spanish. Commented Oct 30, 2019 at 10:36

2 Answers 2

4

Based on this article from the RAE (Real Academia de la Lengua Española: Royal Academy of the Spanish Language), and this other one from the Fundéu (Fundación del Español Urgente: Urgent Spanish Foundation), right now the rule is not to use the grouping separator for 4 digits number, and use a white space as a grouping separator for the rest of the cases. For example:

1000  -> 1000
15000 -> 15 000

However ISO rules recommend to keep the grouping separator even for 4 digits numbers.

1
  • Thanks for point at this! I have finished by doing this ugly thing: ``` formatter.locale = Locale(identifier: "en_US") // Locale.current for spanish devices will be "es_ES" with point character as thousands separator formatter.groupingSeparator = Locale.current.groupingSeparator formatter.decimalSeparator = Locale.current.decimalSeparator ```
    – BuguiBu
    Commented Jan 12, 2021 at 15:40
-1

I don’t recommend using your method. What you should do is return a function for the text;

function addComma(number) local left, num, right = string.match(number, '^([^%d]%d)(%d)(.-)$') return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right end All you have to do is call the function, and the function returns the text with commas. I use this for any game I have that I need currency displayed. Hope this helped!

Also please note, this doesn’t add M+ , K+ , this adds a comma like it does in the Leaderboard. If you wish to know how to add M and K’s to your text here is a video that can explain it well for you;

https://www.youtube.com/watch?v=Mov5znC3yOA

What you do with that is just change what he does for the leaderboard and do it in the text.

Use AddComma function to solve this. As Kensizo said, all you have to do is call the function

https://devforum.roblox.com/t/custom-coin-gui-bug/345991/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.