What is Number Formatting?

Number formatting is rendering numeric values per locale: the decimal separator (period in en_US, comma in de_DE), digit grouping (1,234.56 versus 1.234,56, with some locales grouping differently, such as the Indian numbering system), percent conventions, and currency symbol choice and placement.

Getting it wrong is worse than cosmetic, because separators swap meanings between locales: a string like 1.234 is one and a fraction in English and one thousand two hundred thirty-four in German. Never localize numbers with string manipulation or hardcoded number_format() arguments; the conventions belong to the locale, not the code. Parsing user input has the same problem in reverse, so accept locale-formatted numbers only through a locale-aware parser.

PHP's intl extension provides NumberFormatter, backed by CLDR data, with styles for decimals, percentages, currencies, and spelled-out numbers. Laravel's Number helper wraps it with a clean API. The complementary rule for money: store amounts in minor units or as decimals with a currency code, and treat formatting purely as presentation.

use Illuminate\Support\Number;

Number::format(1234567.891, locale: 'de');          // "1.234.567,891"
Number::currency(99.99, in: 'EUR', locale: 'fr');   // "99,99 €"
Number::percentage(71.5, locale: 'en');             // "72%"

Put the theory to work

LangSyncer manages your Laravel translations live: import lang files, translate with AI and publish without a deploy.

We use cookies to improve your experience and analyze site traffic. Cookie Policy

Cookie Preferences

Essential

Required for the site to work

Analytics

Help us improve the site

Marketing

Personalized ads and content