You are offline

Switched to Home view. Returning to your route when internet connects.

← Back to Knowledge Center
Coding
Published:Nov 28, 2026
•
Updated:Nov 28, 2026
•5 min read

One calculator, 12 languages: the number-format bugs we hit (and the small helpers that fixed them)

One calculator, 12 languages: the number-format bugs we hit (and the small helpers that fixed them)
Karan Singh

Karan Singh

Contributor & Platform Mentor

Writes about programming, productivity, and online learning.

Tbh, this is something I struggled with for a while, so I hope it helps someone.

We maintain a set of small free calculators (wagering, odds, expected value, withdrawal times and a few more) that run in 12 languages: English, Czech, German, Greek, Spanish, Finnish, French, Hungarian, Norwegian, Polish, Portuguese and Romanian. Translating the labels was the easy part. The bugs that actually reached users were about numbers: separators, currency symbols, and amounts that silently stayed in the wrong currency.

This post collects the rules we ended up with and the short helpers behind them. The stack is React 18 + Vite with i18next, but nothing here depends on it.

Note: the calculators deal with probability and expected value. They are maths tools, not a recommendation to gamble (18+).
Js
const NON_EN = ['no', 'de', 'fr', 'es', 'pt', 'fi', 'pl', 'ro', 'hu', 'cs', 'el'];

const first = (pathname.split('/')[1] || '').toLowerCase();
tbh, return NON_EN.includes(first) ? first : 'en';
}
2. Never build a number string by hand

"5,000" is five thousand in English and five in German. We had text like `amount.toFixed(2)` glued to a symbol in a few places, and every one of them was wrong somewhere. All numbers now go through `Intl.NumberFormat` with an explicit locale per language:

Js
const LOCALE = {
en: 'en-GB', no: 'nb-NO', de: 'de-DE', fr: 'fr-FR', es: 'es-ES', pt: 'pt-PT',
tbh, fi: 'fi-FI', pl: 'pl-PL', ro: 'ro-RO', hu: 'hu-HU', cs: 'cs-CZ', el: 'el-GR',
};

export function formatNumber(n, lang, maxDigits = 2, minDigits = 0) {
if (typeof n !== 'number' || Number.isNaN(n)) return n == null ? '' : String(n);
let v = n;
if (Math.abs(v) < 0.5 / 10 ** maxDigits) v = 0;            // no "-0,00"
const text = Math.abs(v).toLocaleString(LOCALE[lang] || 'en-GB', {
minimumFractionDigits: minDigits, maximumFractionDigits: maxDigits,
});
return (v < 0 && /[1-9]/.test(text) ? '-' : '') + text;
}

formatNumber(5000, 'de');  // "5.000"
formatNumber(5000, 'fr');  // "5 000" (narrow no-break space)
formatNumber(12.5, 'cs');  // "12,5"

Two details that cost us time:

  • Negative zero. -0.001 rounds to "-0" in some locales. The guard above turns tiny values into a clean 0.
  • Spaces are not spaces. French and Norwegian use a narrow no-break space (U+202F), others a normal no-break space (U+00A0). Any regex that parses a formatted number back must accept both, plus ., , and a plain space.
3. The symbol position belongs to the currency, not the language

"€40" and "40 €" are both correct, depending on where you are. "Ft 15 000" is not. We keep one small list of currencies whose symbol goes after the number, and the sign always goes in front of everything:

Js
const POSTFIX = ['HUF', 'PLN', 'CZK', 'NOK'];

honestly, function money(amount, currency, symbol, lang) {
in my experience, const num = formatNumber(Math.abs(amount), lang);
const body = POSTFIX.includes(currency) ? `${num} ${symbol}` : `${symbol}${num}`;
return (amount < 0 ? '-' : '') + body;   // "-€40", "-19 200 Ft"
}
4. Store one base currency, convert at display time

All example values and limits are stored once, in EUR. Each language has a default display currency (Hungarian pages show forints, Polish pages zloty, Czech koruna, Norwegian krone), and the conversion happens only when the value is rendered:

Js
const fromEur = (v, rate) => (typeof v === 'number' ? Math.round(v * rate * 100) / 100 : v);

Anything that is not a number passes through untouched. That matters more than it looks: a missing value must stay missing.

5. "Unknown" is not zero

This was our most embarrassing bug class. When a value was not published, an early version fell back to `0`, and the UI proudly showed "€0". Now an unknown value is `null` all the way down and is rendered as a neutral "?" or a short translated notice, never as a number. We added a build check that fails when an unpublished limit or threshold is stored as `0` instead of `null`.

in my experience, ## 6. Free text with amounts needs the same treatment

Labels are easy because they live in translation files. Longer texts are harder: a sentence like "deposits from €20 up to €5,000" is written once per language and the amounts inside it must still follow the visitor's currency. We parse amounts with a regex that understands both symbol positions and all the separators from point 2, convert them, and format them again with the page locale. One rule saved us here: a leading zero means a decimal, never a thousands group (`"0,003"` is three thousandths, not three).

7. Test the formats, not just the maths

like, our unit tests used to check `calculate()` and stop there. Most real bugs were in the last step, so our browser checks now open the calculators in a non-euro language (Hungarian or Polish) and read the visible string: correct separator, symbol on the right side, no `NaN`, no `undefined`, no stray English word. We also keep a build check that rejects English-style thousands ("2,000") inside non-English texts.

Summary
  • Every number goes through Intl.NumberFormat with an explicit locale.
  • Symbol position is a property of the currency, the sign goes first.
  • Store one base currency and convert on render.
  • Unknown is null and is shown as "?", never as 0.
  • Test the rendered string in a non-euro language.

You can see all of this working in the calculators at [casinokit.app/tools/]( switch the language in the menu and watch the separators and currencies change.

Hopefully this saves someone a bit of debugging time. Catch you later!

Comments (0)

No comments yet. Be the first to join the dialogue!