Number helper library.
Methods to make numbers more readable.
int
12
string
'en_US'
string
'currency'
string
'currency_accounting'
string|null
Default currency used by Number::currency()
string
Default currency format used by Number::currency()
array
A list of number formatters indexed by locale and type
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 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.
Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
_setAttributes(\NumberFormatter $formatter, array $options)
Set formatter attributes
\NumberFormatter
$formatter Number formatter instance.
array
$options optional See Number::formatter() for possible options.
\NumberFormatter
config(string $locale, int $type, array $options)
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
$options optional See Number::formatter() for possible options.
currency(mixed $value, ?string $currency, array $options)
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 or not to replace the currency symbol with the international currency code.float|string
$value Value to format.
string|null
$currency optional International currency name such as 'USD', 'EUR', 'JPY', 'CAD'
array
$options optional Options list.
string
Number formatted as a currency.
defaultCurrency(mixed $currency)
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|null
Currency
format(mixed $value, array $options)
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. ']'float|string
$value A floating point number.
array
$options optional An array with options.
string
Formatted number
formatDelta(mixed $value, array $options)
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. ']'float|string
$value A floating point number
array
$options optional Options list.
string
formatted delta
formatter(array $options)
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 or not to replace the currency symbol with the international currency code.array
$options optional An array with options.
\NumberFormatter
The configured formatter instance
getDefaultCurrency()
Getter for default currency
string
Currency
getDefaultCurrencyFormat()
Getter for default currency format
string
Currency Format
ordinal(mixed $value, array $options)
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().
int|float
$value An integer
array
$options optional An array with options.
string
parseFloat(string $value, array $options)
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
$options optional An array with options.
float
point number
precision(mixed $value, int $precision, array $options)
Formats a number with a level of precision.
Options:
locale
: The locale name to use for formatting the number, e.g. fr_FRfloat|string
$value A floating point number.
int
$precision optional The precision of the returned number.
array
$options optional Additional options
string
Formatted float.
setDefaultCurrency(?string $currency)
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
setDefaultCurrencyFormat(mixed $currencyFormat)
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
toPercentage(mixed $value, int $precision, array $options)
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_FRfloat|string
$value A floating point number
int
$precision optional The precision of the returned number
array
$options optional Options
string
Percentage string
toReadableSize(mixed $size)
Returns a formatted-for-humans file size.
int|string
$size Size in bytes
string
Human readable size
Default currency used by Number::currency()
string|null
Default currency format used by Number::currency()
string
A list of number formatters indexed by locale and type
array
© 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.1/class-Cake.I18n.Number.html