Commas and Dots Mean Different Things in Different Locales
Table of Contents
I ran into an issue where a price string was being parsed incorrectly. The culprit: locale differences in number formatting.
The Two Conventions #
| Convention | Thousands separator | Decimal separator | Example |
|---|---|---|---|
| US/UK (and most of Asia) | comma , | dot . | 1,234.56 |
| Most of EU (Germany, France, Poland, etc.) | dot . | comma , | 1.234,56 |
Both represent the same number: one thousand two hundred thirty-four and fifty-six hundredths.
Why This Bites You #
When you receive a price as a string - say from a CSV export, an API, or user input - 5,069 could mean:
- 5069 (five thousand sixty-nine) in US/UK format, where the comma is a thousands separator
- 5.069 (roughly five) in EU format, where the comma is a decimal separator
If your system assumes one convention and the data source uses the other, you’ll silently store the wrong value. No error, no exception - just a number that’s off by orders of magnitude.
The Broader Lesson #
Number formatting is one of those localization details that’s easy to overlook until it corrupts your data. Other fun variations:
- Switzerland uses an apostrophe as thousands separator:
1'234.56 - India groups digits differently:
1,23,456.78(lakhs and crores) - Some systems use a thin space as thousands separator:
1 234,56
If you’re parsing numbers from external sources, always be explicit about which locale convention you expect - and document it for anyone feeding data into your system.