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.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 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

  • CacheHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

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

  • $_engine protected
    CakeNumber
    CakeNumber 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
mixed
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 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() 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() 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() 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() 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() 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() 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() 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

$_engine ¶

protected CakeNumber

CakeNumber instance

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