Class NumberHelper
Number helper library.
Methods to make numbers more readable.
- AppHelper
- NumberHelper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html
See:
CakeNumber
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/NumberHelper.php
Properties summary
-
$_engine
protected
Method Summary
- __call() publicCall methods from CakeNumber utility class
- __construct() publicDefault Constructor
- addFormat() public
Add 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:
-
engine
Class name to use to replace CakeNumber functionality The class needs to be placed in theUtility
directory.
Parameters
-
View
$View
- The View this helper is being attached to.
- array
$settings
optional array() - Configuration settings for the helper
Throws
CakeException
When 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
http://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
$currency
optional 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
$options
optional array() - Options list.
Returns
stringNumber formatted as a currency.
See
CakeNumber::currency()Link
http://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
$options
optional 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
http://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
$precision
optional 3 - The precision of the returned number.
Returns
floatFormatted float.
See
CakeNumber::precision()Link
http://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
$precision
optional 2 - The precision of the returned number
- array
$options
optional array() - Options
Returns
stringPercentage string
See
CakeNumber::toPercentage()Link
http://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
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSizeProperties detail
© 2005–2016 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.9/class-NumberHelper.html