Source: www.amitmerchant.com

Human readable number formatting in PHP
Numbers are tricky because they have been used as a metric for a lot of things. Currency, scale, weather, science to name a few. And since numbers are associated with several different things, it’s important to represent them in a way humans can understand.

The class consists of numerous methods using which you can format numbers, currencies, and percentages according to the specified or default locale.

class NumberFormatter { /* Methods */ public __construct(string $locale, int $style, ?string $pattern = null) public static create(string $locale, int $style, ?string $pattern = null): ?NumberFormatter public formatCurrency(float $amount, string $currency): string|false public format(int|float $num, int $type = NumberFormatter::TYPE_DEFAULT): string|false public getAttribute(int $attribute): int|float|false public getErrorCode(): int public getErrorMessage(): string public getLocale(int $type = ULOC_ACTUAL_LOCALE): string|false public getPattern(): string|false public getSymbol(int $symbol): string|false public getTextAttribute(int $attribute): string|false public parseCurrency(string $string, string &$currency, int &$offset = null): float|false public parse(string $string, int $type = NumberFormatter::TYPE_DOUBLE, int &$offset = null): int|float|false public setAttribute(int $attribute, int|float $value): bool public setPattern(string $pattern): bool public setSymbol(int $symbol, string $value): bool public setTextAttribute(int $attribute, string $value): bool }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners