'Problem formatting 4-digit integers with thousands separator
print(String(format: "%d", locale: Locale.current, 33600))
//prints 33.600
print(String(format: "%d", locale: Locale.current, 3360))
//prints 3360 without thousands separator
Same issue using NumberFormatter.
Solution 1:[1]
Here in the US, where the thousands separator is a comma, the following code:
print(String(format: "%d", locale: Locale.current, 33600))
print(String(format: "%d", locale: Locale.current, 3360))
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
print(formatter.string(from: 33600)!)
print(formatter.string(from: 3360)!)
Outputs:
33,600
3,360
33,600
3,360
So it works as expected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Duncan C |
