Class NumberHelper

Number helper library.

Methods to make numbers more readable.

AppHelper
Extended by NumberHelper
Package: Cake\View\Helper
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

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.
  • Getter/setter for default currency
  • format() public
    Formats a number into a currency format.
  • precision() public
    Formats a number with a level of precision.
  • Formats a number into a percentage string.
  • Returns 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

mixed
Whatever 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 the Utility 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::addFormat

currency()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

string
Number formatted as a currency.

See

CakeNumber::currency()

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency

defaultCurrency()source public

defaultCurrency( string $currency )

Getter/setter for default currency

Parameters

string $currency
The currency to be used in the future.

Returns

string
Currency

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

string
formatted number

See

CakeNumber::format()

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format

precision()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

float
Formatted float.

See

CakeNumber::precision()

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision

toPercentage()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

string
Percentage string

See

CakeNumber::toPercentage()

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage

toReadableSize()source public

toReadableSize( integer $size )

Returns a formatted-for-humans file size.

Parameters

integer $size
Size in bytes

Returns

string
Human readable size

See

CakeNumber::toReadableSize()

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize

Properties detail

$_enginesource

protected CakeNumber

CakeNumber instance

null

© 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