Number helper library.
Methods to make numbers more readable.
string
'en_US'
string
'currency'
string|null
array
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.
_setAttributes( NumberFormatter $formatter , array $options [] )
Set formatter attributes
$formatter
$options
optional [] config( string $locale , integer $type Cake\I18n\NumberFormatter::DECIMAL , array $options [] )
Configure formatters.
$locale
$type
optional Cake\I18n\NumberFormatter::DECIMAL $options
optional [] currency( float $value , string|null $currency null , 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 #,###.00useIntlCode
- Whether or not to replace the currency symbol with the international currency code.$value
$currency
optional null $options
optional [] defaultCurrency( string|boolean|null $currency null )
Getter/setter for default currency
$currency
optional null Default currency string to be used by currency() if $currency argument is not provided. If boolean false is passed, it will clear the currently stored value
format( float $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 #,###.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. ']'$value
$options
optional [] formatDelta( float $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. ']'$value
$options
optional [] 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 #,###.00useIntlCode
- Whether or not to replace the currency symbol with the international currency code.$options
optional [] ordinal( integer|float $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().
$value
$options
optional [] 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.$value
$options
optional [] precision( float $value , integer $precision 3 , array $options [] )
Formats a number with a level of precision.
Options:
locale
: The locale name to use for formatting the number, e.g. fr_FR$value
$precision
optional 3 $options
optional [] toPercentage( float $value , integer $precision 2 , 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_FR$value
$precision
optional 2 $options
optional [] toReadableSize( integer $size )
Returns a formatted-for-humans file size.
$size
protected static string|null
Default currency used by Number::currency()
null
© 2005–2017 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/3.4/class-Cake.I18n.Number.html