CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeNumber
  • CakeTime
  • ClassRegistry
  • Debugger
  • File
  • Folder
  • Hash
  • Inflector
  • ObjectCollection
  • Sanitize
  • Security
  • Set
  • String
  • Validation
  • Xml

Class CakeNumber

Number helper library.

Methods to make numbers more readable.

Package: Cake\Utility
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Utility/CakeNumber.php

Properties summary

  • $_currencies protected static
    array

    Currencies supported by the helper. You can add additional currency formats with CakeNumber::addFormat

  • $_currencyDefaults protected static
    array
    Default options for currency formats
  • $_numberFormatSupport protected static
    boolean
    If native number_format() should be used. If >= PHP5.4

Method Summary

  • _numberFormat() protected static
    Alternative number_format() to accommodate multibyte decimals and thousands < PHP 5.4
  • addFormat() public static

    Add a currency format to the Number helper. Makes reusing currency formats easier.

  • currency() public static
    Formats a number into a currency format.
  • format() public static
    Formats a number into a currency format.
  • precision() public static
    Formats a number with a level of precision.
  • toPercentage() public static
    Formats a number into a percentage string.
  • toReadableSize() public static
    Returns a formatted-for-humans file size.

Method Detail

_numberFormat() protected static ¶

_numberFormat( float $number , integer $places = 0 , string $decimals = '.' , string $thousands = ',' )

Alternative number_format() to accommodate multibyte decimals and thousands < PHP 5.4

Parameters
float $number
integer $places optional 0
string $decimals optional '.'
string $thousands optional ','
Returns
string

addFormat() public static ¶

addFormat( string $formatName , array $options )

Add a currency format to the Number helper. Makes reusing currency formats easier.

{{{ $number->addFormat('NOK', array('before' => 'Kr. ')); }}}

You can now use NOK as a shortform when formatting currency amounts.

{{{ $number->currency($value, 'NOK'); }}}

Added formats are merged with the defaults defined in CakeNumber::$_currencyDefaults See CakeNumber::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
NumberHelper::currency()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::addFormat

currency() public static ¶

currency( float $number , string $currency = 'USD' , array $options = array() )

Formats a number into a currency format.

Options

  • wholeSymbol - The currency symbol to use for whole numbers, greater than 1, or less than -1.
  • wholePosition - The position the whole symbol should be placed valid options are 'before' & 'after'.
  • fractionSymbol - The currency symbol to use for fractional numbers.
  • fractionPosition - The position the fraction symbol should be placed valid options are 'before' & 'after'.
  • before - The currency symbol to place before whole numbers ie. '$'. before is an alias for wholeSymbol.
  • after - The currency symbol to place after decimal numbers ie. 'c'. Set to boolean false to use no decimal symbol. eg. 0.35 => $0.35. after is an alias for fractionSymbol
  • zero - The text to use for zero values, can be a string or a number. ie. 0, 'Free!'
  • places - Number of decimal places to use. ie. 2
  • thousands - Thousands separator ie. ','
  • decimals - Decimal separator symbol ie. '.'
  • negative - Symbol for negative numbers. If equal to '()', the number will be wrapped with ( and )
  • escape - Should the output be escaped for html special characters. The default value for this option is controlled by the currency settings. By default the EUR, and GBP contain HTML encoded symbols. If you require non HTML encoded symbols you will need to update the settings with the correct bytes.
Parameters
float $number
string $currency optional 'USD'

Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise set at least 'before' and 'after' options.

array $options optional array()
Returns
string
Number formatted as a currency.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency

format() public static ¶

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 int then places, if string then before, if (,.-) then use it or array with places and before keys

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

precision() public static ¶

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.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision

toPercentage() public static ¶

toPercentage( float $number , integer $precision = 2 )

Formats a number into a percentage string.

Parameters
float $number
A floating point number
integer $precision optional 2
The precision of the returned number
Returns
string
Percentage string
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage

toReadableSize() public static ¶

toReadableSize( integer $size )

Returns a formatted-for-humans file size.

Parameters
integer $size
Size in bytes
Returns
string
Human readable size
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize

Properties detail

$_currencies ¶

protected static array

Currencies supported by the helper. You can add additional currency formats with CakeNumber::addFormat

array(
    'USD' => array(
        'wholeSymbol' => '$', 'wholePosition' => 'before', 'fractionSymbol' => 'c', 'fractionPosition' => 'after',
        'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true
    ),
    'GBP' => array(
        'wholeSymbol' => '&#163;', 'wholePosition' => 'before', 'fractionSymbol' => 'p', 'fractionPosition' => 'after',
        'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()','escape' => false
    ),
    'EUR' => array(
        'wholeSymbol' => '&#8364;', 'wholePosition' => 'before', 'fractionSymbol' => false, 'fractionPosition' => 'after',
        'zero' => 0, 'places' => 2, 'thousands' => '.', 'decimals' => ',', 'negative' => '()', 'escape' => false
    )
)

$_currencyDefaults ¶

protected static array

Default options for currency formats

array(
    'wholeSymbol' => '', 'wholePosition' => 'before', 'fractionSymbol' => '', 'fractionPosition' => 'after',
    'zero' => '0', 'places' => 2, 'thousands' => ',', 'decimals' => '.','negative' => '()', 'escape' => true,
)

$_numberFormatSupport ¶

protected static boolean

If native number_format() should be used. If >= PHP5.4

null
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs