Number helper library.
Methods to make numbers more readable.
int 12
ICU Constant for accounting format; not yet widely supported by INTL library. This will be able to go away once CakePHP minimum PHP requirement is 7.4.1 or higher. See UNUM_CURRENCY_ACCOUNTING in https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/unum_8h.html
string 'en_US'
Default locale
string 'currency'
Format type to format as currency
string 'currency_accounting'
Format type to format as currency, accounting style (negative numbers in parentheses)
string|nullDefault currency used by Number::currency()
string|nullDefault currency format used by Number::currency()
array<string, array<int, mixed>>A list of number formatters indexed by locale and type
Set formatter attributes
Configure formatters.
Formats a number into a currency format.
Getter/setter for default currency. This behavior is deprecated and will be removed in future versions of CakePHP.
Formats a number into the correct locale format
Formats a number into the correct locale format to show deltas (signed differences in value).
Returns a formatter object that can be reused for similar formatting task under the same locale and options. This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed.
Getter for default currency
Getter for default currency format
Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
Parse a localized numeric string and transform it in a float point
Formats a number with a level of precision.
Setter for default currency
Setter for default currency format
Formats a number into a percentage string.
Returns a formatted-for-humans file size.
_setAttributes(NumberFormatter $formatter, array<string, mixed> $options = []): NumberFormatter
Set formatter attributes
NumberFormatter $formatter Number formatter instance.
array<string, mixed> $options optional See Number::formatter() for possible options.
NumberFormatterconfig(string $locale, int $type = NumberFormatter::DECIMAL, array<string, mixed> $options = []): void
Configure formatters.
string $locale The locale name to use for formatting the number, e.g. fr_FR
int $type optional The formatter type to construct. Defaults to NumberFormatter::DECIMAL.
array<string, mixed> $options optional See Number::formatter() for possible options.
voidcurrency(string|float $value, string|null $currency = null, array<string, mixed> $options = []): string
Formats a number into a currency format.
locale - The locale name to use for formatting the number, e.g. fr_FRfractionSymbol - The currency symbol to use for fractional numbers.fractionPosition - The position the fraction symbol should be placed valid options are 'before' & 'after'.before - Text to display before the rendered numberafter - Text to display after the rendered numberzero - The text to use for zero values, can be a string or a number. e.g. 0, 'Free!'places - Number of decimal places to use. e.g. 2precision - Maximum Number of decimal places to use, e.g. 2pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00useIntlCode - Whether to replace the currency symbol with the international currency code.string|float $value Value to format.
string|null $currency optional International currency name such as 'USD', 'EUR', 'JPY', 'CAD'
array<string, mixed> $options optional Options list.
stringdefaultCurrency(string|false|null $currency = null): string|null
Getter/setter for default currency. This behavior is deprecated and will be removed in future versions of CakePHP.
string|false|null $currency optional Default currency string to be used by {@link currency()} if $currency argument is not provided. If boolean false is passed, it will clear the currently stored value
string|nullformat(string|int|float $value, array<string, mixed> $options = []): string
Formats a number into the correct locale format
Options:
places - Minimum number or decimals to use, e.g 0precision - Maximum Number of decimal places to use, e.g. 2pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00locale - The locale name to use for formatting the number, e.g. fr_FRbefore - The string to place before whole numbers, e.g. '['after - The string to place after decimal numbers, e.g. ']'string|int|float $value A floating point number.
array<string, mixed> $options optional An array with options.
stringformatDelta(string|float $value, array<string, mixed> $options = []): string
Formats a number into the correct locale format to show deltas (signed differences in value).
places - Minimum number or decimals to use, e.g 0precision - Maximum Number of decimal places to use, e.g. 2locale - The locale name to use for formatting the number, e.g. fr_FRbefore - The string to place before whole numbers, e.g. '['after - The string to place after decimal numbers, e.g. ']'string|float $value A floating point number
array<string, mixed> $options optional Options list.
stringformatter(array<string, mixed> $options = []): NumberFormatter
Returns a formatter object that can be reused for similar formatting task under the same locale and options. This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed.
locale - The locale name to use for formatting the number, e.g. fr_FRtype - The formatter type to construct, set it to currency if you need to format numbers representing money or a NumberFormatter constant.places - Number of decimal places to use. e.g. 2precision - Maximum Number of decimal places to use, e.g. 2pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00useIntlCode - Whether to replace the currency symbol with the international currency code.array<string, mixed> $options optional An array with options.
NumberFormattergetDefaultCurrency(): string
Getter for default currency
stringgetDefaultCurrencyFormat(): string
Getter for default currency format
stringordinal(float|int $value, array<string, mixed> $options = []): string
Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
type - The formatter type to construct, set it to currency if you need to format numbers representing money or a NumberFormatter constant.For all other options see formatter().
float|int $value An integer
array<string, mixed> $options optional An array with options.
stringparseFloat(string $value, array<string, mixed> $options = []): float
Parse a localized numeric string and transform it in a float point
Options:
locale - The locale name to use for parsing the number, e.g. fr_FRtype - The formatter type to construct, set it to currency if you need to parse numbers representing money.string $value A numeric string.
array<string, mixed> $options optional An array with options.
floatprecision(string|float $value, int $precision = 3, array<string, mixed> $options = []): string
Formats a number with a level of precision.
Options:
locale: The locale name to use for formatting the number, e.g. fr_FRstring|float $value A floating point number.
int $precision optional The precision of the returned number.
array<string, mixed> $options optional Additional options
stringsetDefaultCurrency(string|null $currency = null): void
Setter for default currency
string|null $currency optional Default currency string to be used by {@link currency()} if $currency argument is not provided. If null is passed, it will clear the currently stored value
voidsetDefaultCurrencyFormat(string|null $currencyFormat = null): void
Setter for default currency format
string|null $currencyFormat optional Default currency format to be used by currency() if $currencyFormat argument is not provided. If null is passed, it will clear the currently stored value
voidtoPercentage(string|float $value, int $precision = 2, array<string, mixed> $options = []): string
Formats a number into a percentage string.
Options:
multiply: Multiply the input value by 100 for decimal percentages.locale: The locale name to use for formatting the number, e.g. fr_FRstring|float $value A floating point number
int $precision optional The precision of the returned number
array<string, mixed> $options optional Options
stringtoReadableSize(string|int $size): string
Returns a formatted-for-humans file size.
string|int $size Size in bytes
stringDefault currency used by Number::currency()
string|nullDefault currency format used by Number::currency()
string|nullA list of number formatters indexed by locale and type
array<string, array<int, mixed>>
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.I18n.Number.html