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:
CakeNumber
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/NumberHelper.php
Properties summary
-
$_engine
protectedCakeNumber instance
Method Summary
-
__call() public
Call methods from CakeNumber utility class -
__construct() public
Default Constructor -
addFormat() public
Add a currency format to the Number helper. Makes reusing currency formats easier.
-
currency() public
Formats a number into a currency format. -
defaultCurrency() public
Getter/setter for default currency -
format() public
Formats a number into a currency format. -
precision() public
Formats a number with a level of precision. -
toPercentage() public
Formats a number into a percentage string. -
toReadableSize() public
Returns a formatted-for-humans file size.
Method Detail
__call() 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
Whatever is returned by called method, or false on failure
__construct() 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
addFormat() 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
Link
currency() 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
Number formatted as a currency.
See
Link
defaultCurrency() public ¶
defaultCurrency( string $currency )
Getter/setter for default currency
Parameters
- string $currency
- The currency to be used in the future.
Returns
Currency
See
format() 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
formatted number
See
Link
precision() 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
Formatted float.
See
Link
toPercentage() 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
Percentage string
See
Link
toReadableSize() public ¶
toReadableSize( integer $size )
Returns a formatted-for-humans file size.
Parameters
- integer $size
- Size in bytes
Returns
Human readable size