NumberFormatter

NumberFormatter::create(string $locale, int $style, ?string $pattern = null): ?NumberFormatter

ICU's binding for number/currency/percent formatting: renders locale-specific number strings by locale and style (DECIMAL/CURRENCY/PERCENT/SPELLL and friends), with a reversible parse(). The example pins en_US asserting "1,234.56" — pure numeric patterns are stable across ICU versions; currency symbols drift far more, so they are discussed in the notes only, never in code.

C C23

C23
#include <locale.h>
#include <stdio.h>

int main(void) {
    /* C stdlib: no locale-aware number formatting API; the POSIX ' flag groups
       per LC_NUMERIC, and the C locale defines no grouping separator at all */
    setlocale(LC_NUMERIC, "C");
    printf("%'.2f\n", 1234.56); /* -> "1234.56": nothing to insert in C locale */
    printf("%.2f\n", 1234.56);  /* plain conversion is always locale-free */
    return 0;
}
Output
1234.56
1234.56

C++ C++26

C++26
#include <clocale>
#include <cstdio>

int main() {
    // same as C: the ' flag groups per LC_NUMERIC; C locale has no separator
    std::setlocale(LC_NUMERIC, "C");
    std::printf("%'.2f\n", 1234.56); // -> "1234.56"
    return 0;
}
Output
1234.56

C# v11.0.100

v11.0.100
// "N2" is the fixed-precision grouped pattern; the culture supplies the symbols
using System.Globalization;

Console.WriteLine((1234.56).ToString("N2", CultureInfo.GetCultureInfo("en-US")));
Console.WriteLine((1234.56).ToString("N2", CultureInfo.GetCultureInfo("de-DE")));
Output
1,234.56
1.234,56

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
	// std formatting is locale-free; humanized grouping needs golang.org/x/text
	fmt.Printf("%.2f\n", 1234.56)
}
Output
1234.56

Java v27.0.1

v27.0.1
import java.text.NumberFormat;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        // NumberFormat is the JDK-native sibling of ICU's NumberFormatter
        System.out.println(NumberFormat.getNumberInstance(Locale.US).format(1234.56));
        System.out.println(NumberFormat.getNumberInstance(Locale.GERMANY).format(1234.56));
    }
}
Output
1,234.56
1.234,56

JavaScript v26.13.1

v26.13.1
// Intl.NumberFormat is the same ICU-backed family as PHP's NumberFormatter
console.log(new Intl.NumberFormat('en-US').format(1234.56));
console.log(new Intl.NumberFormat('de-DE').format(1234.56));
Output
1,234.56
1.234,56

PHP v8.6.0

v8.6.0
// NumberFormatter binds ICU: one formatter per locale, the style picks the pattern
$n = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo $n->format(1234.56), "\n";   // en_US: comma grouping, dot decimal
echo $n->parse('1,234.56'), "\n"; // round-trip: locale string back to a number
$de = new NumberFormatter('de_DE', NumberFormatter::DECIMAL);
echo $de->format(1234.56), "\n";  // de_DE: dot grouping, comma decimal
Output
1,234.56
1234.56
1.234,56

Python v3.15.2

v3.15.2
# stdlib formatting is locale-independent: separators come from the format spec
print(format(1234.56, ',.2f'))  # comma grouping
print(format(1234.56, '_.2f'))  # underscore grouping
# locale-aware formatting needs the locale module + OS-installed locales (see notes);
# Babel (third-party) is the ICU-backed equivalent of NumberFormatter
Output
1,234.56
1_234.56

Rust v1.99.1

v1.99.1
fn main() {
    // std formatting is locale-free; ICU-style grouping needs external crates
    println!("{:.2}", 1234.56);
}
Output
1234.56

TypeScript v26.13.1

v26.13.1
// Intl.NumberFormat is the same ICU-backed family as PHP's NumberFormatter
const us: Intl.NumberFormat = new Intl.NumberFormat('en-US');
const de: Intl.NumberFormat = new Intl.NumberFormat('de-DE');
console.log(us.format(1234.56));
console.log(de.format(1234.56));
Output
1,234.56
1.234,56

Language differences

PHP: NumberFormatter (alias family numfmt_*) works by locale + style: DECIMAL (plain numbers), CURRENCY/CURRENCY_ACCOUNTING (7.4.1+), PERCENT, SCIENTIFIC, SPELLLOUT/ORDINAL/DURATION (rule-based, tied to ICU version data), plus DECIMAL_COMPACT_SHORT/LONG, CURRENCY_ISO and more since 8.5. format() renders, parse() reverses, and formatCurrency() requires an ISO currency code (e.g. USD — the formatter knows no exchange rate, so swapping the code re-denominates the same number). Precision is governed by setAttribute(MIN/MAX_FRACTION_DIGITS) (at most 2 fraction digits by default, per the manual's user note).

ICU-version sensitivity analysis: "1,234.56" from en_US DECIMAL is a pure numeric pattern — the grouping/decimal symbols come from the locale's decimalFormat pattern, unchanged for decades (comma + dot), byte-identical across ICU versions. What really drifts: SPELLLOUT (spelling rules grow with CLDR), CURRENCY (the $ vs US$ symbol, negative accounting formats, even currency-name plurals can change across CLDR releases) — which is why currency style is prose-only here: new NumberFormatter('en_US', NumberFormatter::CURRENCY) + formatCurrency(1234.56, 'USD') typically yields "$1,234.56" (accounting style renders negatives as "($1,234.56)"); never hard-code the symbol — read it via getSymbol(CURRENCY_SYMBOL).

C/C++: no locale-aware number formatting in the standard library; the POSIX printf("'%f") grouping flag depends on LC_NUMERIC and the C locale defines no separator (the example prints the value unchanged); production code uses ICU or hand-rolled grouping.

C#: ToString("N2", culture) — N is the fixed-precision grouped pattern and the culture supplies the symbols; "C" is the currency pattern (symbols from .NET's built-in data — also prefer reading them at runtime).

Java: NumberFormat.getNumberInstance(culture); getCurrencyInstance + setCurrency(Currency.getInstance("USD")).

JS/TS: Intl.NumberFormat is the sibling native API; {style:'currency', currency:'USD'} is the currency style.

Python: stdlib format(v, ',.2f') is always locale-free; locale.format_string depends on OS locales; ICU-level via Babel's format_decimal(v, locale='en_US').

Go: fmt/strconv have no locale; golang.org/x/text/message + language.English Printf("%.2f") is what groups.

Rust: std formatting has no locale; ICU-level via the icu_decimal/fixed_decimal crates.

Side-by-side: the ICU family (PHP/JS/Java) and the built-in-data school (C#) emit symbols per locale, while C/C++/Python-stdlib/Go/Rust-stdlib leave formatting entirely to you — the projection of "the global locale is dead, long live explicit parameters" onto number formatting.