On this page
Class NumberHelper
Number helper library.
Methods to make numbers more readable.
- AppHelper
- NumberHelper 
Link: https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html
See:
CakeNumberCopyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/NumberHelper.php
Properties summary
- 
    CakeNumber instance$_engineprotected
Method Summary
- 
    __call() publicCall methods from CakeNumber utility class
- 
    __construct() publicDefault Constructor
- 
    addFormat() publicAdd a currency format to the Number helper. Makes reusing currency formats easier. 
- 
    currency() publicFormats a number into a currency format.
- 
    defaultCurrency() publicGetter/setter for default currency
- 
    format() publicFormats a number into a currency format.
- 
    precision() publicFormats a number with a level of precision.
- 
    toPercentage() publicFormats a number into a percentage string.
- 
    toReadableSize() publicReturns a formatted-for-humans file size.
Method Detail
__call()source public
__call( string $method , array $params )Call methods from CakeNumber utility class
Parameters
- 
     string $method
- Method to call.
- 
     array $params
- Parameters to pass to method.
Returns
mixedWhatever is returned by called method, or false on failure
__construct()source public
__construct( View $View , array $settings array() )Default Constructor
Settings:
- engineClass name to use to replace CakeNumber functionality The class needs to be placed in the- Utilitydirectory.
Parameters
- View- $View
- The View this helper is being attached to.
- 
     array $settingsoptional array()
- Configuration settings for the helper
Throws
CakeExceptionWhen the engine class could not be found.
addFormat()source public
addFormat( string $formatName , array $options )Add a currency format to the Number helper. Makes reusing currency formats easier.
$this->Number->addFormat('NOK', array('before' => 'Kr. ')); ```
You can now use `NOK` as a shortform when formatting currency amounts.$this->Number->currency($value, 'NOK'); ```
Added formats are merged with the defaults defined in Cake\Utility\Number::$_currencyDefaults See Cake\Utility\Number::currency() for more information on the various options and their function.
Parameters
- 
     string $formatName
- The format name to be used in the future.
- 
     array $options
- The array of options for this format.
See
CakeNumber::addFormat()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::addFormatcurrency()source public
currency( float $number , string $currency null , array $options array() )Formats a number into a currency format.
Parameters
- 
     float $number
- Number to format.
- 
     string $currencyoptional null
- 
     Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise set at least 'before' and 'after' options. 'USD' is the default currency, use CakeNumber::defaultCurrency() to change this default. 
- 
     array $optionsoptional array()
- Options list.
Returns
stringNumber formatted as a currency.
See
CakeNumber::currency()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currencydefaultCurrency()source public
defaultCurrency( string $currency )Getter/setter for default currency
Parameters
- 
     string $currency
- The currency to be used in the future.
Returns
stringCurrency
See
CakeNumber::defaultCurrency()format()source public
format( float $number , integer $options false )Formats a number into a currency format.
Parameters
- 
     float $number
- A floating point number
- 
     integer $optionsoptional false
- 
     If integer then places, if string then before, if (,.-) then use it or array with places and before keys 
Returns
stringformatted number
See
CakeNumber::format()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::formatprecision()source public
precision( float $number , integer $precision 3 )Formats a number with a level of precision.
Parameters
- 
     float $number
- A floating point number.
- 
     integer $precisionoptional 3
- The precision of the returned number.
Returns
floatFormatted float.
See
CakeNumber::precision()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precisiontoPercentage()source public
toPercentage( float $number , integer $precision 2 , array $options array() )Formats a number into a percentage string.
Options:
- multiply: Multiply the input value by 100 for decimal percentages.
Parameters
- 
     float $number
- A floating point number
- 
     integer $precisionoptional 2
- The precision of the returned number
- 
     array $optionsoptional array()
- Options
Returns
stringPercentage string
See
CakeNumber::toPercentage()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentagetoReadableSize()source public
toReadableSize( integer $size )Returns a formatted-for-humans file size.
Parameters
- 
     integer $size
- Size in bytes
Returns
stringHuman readable size
See
CakeNumber::toReadableSize()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSizeProperties detail
© 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/2.10/class-NumberHelper.html