CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ChainMessagesLoader
  • Date
  • FrozenDate
  • FrozenTime
  • I18n
  • MessagesFileLoader
  • Number
  • PluralRules
  • Time
  • TranslatorRegistry

Traits

  • DateFormatTrait

Class Number

Number helper library.

Methods to make numbers more readable.

Namespace: Cake\I18n
Link: https://book.cakephp.org/3.0/en/core-libraries/number.html
Location: I18n/Number.php

Constants summary

  • string
    DEFAULT_LOCALE ¶
    'en_US'
  • string
    FORMAT_CURRENCY ¶
    'currency'

Properties summary

  • $_defaultCurrency protected static
    string|null
    Default currency used by Number::currency()
  • $_formatters protected static
    array
    A list of number formatters indexed by locale and type

Method Summary

  • _setAttributes() protected static
    Set formatter attributes
  • config() public static
    Configure formatters.
  • currency() public static
    Formats a number into a currency format.
  • defaultCurrency() public static
    Getter/setter for default currency
  • format() public static
    Formats a number into the correct locale format
  • formatDelta() public static
    Formats a number into the correct locale format to show deltas (signed differences in value).
  • formatter() public static

    Returns a formatter object that can be reused for similar formatting task under the same locale and options. This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed.

  • ordinal() public static
    Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])
  • parseFloat() public static
    Parse a localized numeric string and transform it in a float point
  • 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

_setAttributes() protected static ¶

_setAttributes( NumberFormatter $formatter , array $options = [] )

Set formatter attributes

Parameters
NumberFormatter $formatter
Number formatter instance.
array $options optional []
See Number::formatter() for possible options.
Returns
NumberFormatter

config() public static ¶

config( string $locale , integer $type = Cake\I18n\NumberFormatter::DECIMAL , array $options = [] )

Configure formatters.

Parameters
string $locale
The locale name to use for formatting the number, e.g. fr_FR
integer $type optional Cake\I18n\NumberFormatter::DECIMAL
The formatter type to construct. Defaults to NumberFormatter::DECIMAL.
array $options optional []
See Number::formatter() for possible options.

currency() public static ¶

currency( float $value , string|null $currency = null , array $options = [] )

Formats a number into a currency format.

Options

  • locale - The locale name to use for formatting the number, e.g. fr_FR
  • fractionSymbol - The currency symbol to use for fractional numbers.
  • fractionPosition - The position the fraction symbol should be placed valid options are 'before' & 'after'.
  • before - Text to display before the rendered number
  • after - Text to display after the rendered number
  • zero - The text to use for zero values, can be a string or a number. e.g. 0, 'Free!'
  • places - Number of decimal places to use. e.g. 2
  • precision - Maximum Number of decimal places to use, e.g. 2
  • pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00
  • useIntlCode - Whether or not to replace the currency symbol with the international currency code.
Parameters
float $value
Value to format.
string|null $currency optional null
International currency name such as 'USD', 'EUR', 'JPY', 'CAD'
array $options optional []
Options list.
Returns
string
Number formatted as a currency.

defaultCurrency() public static ¶

defaultCurrency( string|boolean|null $currency = null )

Getter/setter for default currency

Parameters
string|boolean|null $currency optional null

Default currency string to be used by currency() if $currency argument is not provided. If boolean false is passed, it will clear the currently stored value

Returns
string|null
Currency

format() public static ¶

format( float $value , array $options = [] )

Formats a number into the correct locale format

Options:

  • places - Minimum number or decimals to use, e.g 0
  • precision - Maximum Number of decimal places to use, e.g. 2
  • pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00
  • locale - The locale name to use for formatting the number, e.g. fr_FR
  • before - The string to place before whole numbers, e.g. '['
  • after - The string to place after decimal numbers, e.g. ']'
Parameters
float $value
A floating point number.
array $options optional []
An array with options.
Returns
string
Formatted number

formatDelta() public static ¶

formatDelta( float $value , array $options = [] )

Formats a number into the correct locale format to show deltas (signed differences in value).

Options

  • places - Minimum number or decimals to use, e.g 0
  • precision - Maximum Number of decimal places to use, e.g. 2
  • locale - The locale name to use for formatting the number, e.g. fr_FR
  • before - The string to place before whole numbers, e.g. '['
  • after - The string to place after decimal numbers, e.g. ']'
Parameters
float $value
A floating point number
array $options optional []
Options list.
Returns
string
formatted delta

formatter() public static ¶

formatter( array $options = [] )

Returns a formatter object that can be reused for similar formatting task under the same locale and options. This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed.

Options

  • locale - The locale name to use for formatting the number, e.g. fr_FR
  • type - The formatter type to construct, set it to currency if you need to format numbers representing money or a NumberFormatter constant.
  • places - Number of decimal places to use. e.g. 2
  • precision - Maximum Number of decimal places to use, e.g. 2
  • pattern - An ICU number pattern to use for formatting the number. e.g #,##0.00
  • useIntlCode - Whether or not to replace the currency symbol with the international currency code.
Parameters
array $options optional []
An array with options.
Returns
NumberFormatter
The configured formatter instance

ordinal() public static ¶

ordinal( integer|float $value , array $options = [] )

Returns a formatted integer as an ordinal number string (e.g. 1st, 2nd, 3rd, 4th, [...])

Options

  • type - The formatter type to construct, set it to currency if you need to format numbers representing money or a NumberFormatter constant.

For all other options see formatter().

Parameters
integer|float $value
An integer
array $options optional []
An array with options.
Returns
string

parseFloat() public static ¶

parseFloat( string $value , array $options = [] )

Parse a localized numeric string and transform it in a float point

Options:

  • locale - The locale name to use for parsing the number, e.g. fr_FR
  • type - The formatter type to construct, set it to currency if you need to parse numbers representing money.
Parameters
string $value
A numeric string.
array $options optional []
An array with options.
Returns
float
point number

precision() public static ¶

precision( float $value , integer $precision = 3 , array $options = [] )

Formats a number with a level of precision.

Options:

  • locale: The locale name to use for formatting the number, e.g. fr_FR
Parameters
float $value
A floating point number.
integer $precision optional 3
The precision of the returned number.
array $options optional []
Additional options
Returns
string
Formatted float.
Link
https://book.cakephp.org/3.0/en/core-libraries/number.html#formatting-floating-point-numbers

toPercentage() public static ¶

toPercentage( float $value , integer $precision = 2 , array $options = [] )

Formats a number into a percentage string.

Options:

  • multiply: Multiply the input value by 100 for decimal percentages.
  • locale: The locale name to use for formatting the number, e.g. fr_FR
Parameters
float $value
A floating point number
integer $precision optional 2
The precision of the returned number
array $options optional []
Options
Returns
string
Percentage string
Link
https://book.cakephp.org/3.0/en/core-libraries/number.html#formatting-percentages

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
https://book.cakephp.org/3.0/en/core-libraries/number.html#interacting-with-human-readable-values

Properties detail

$_defaultCurrency ¶

protected static string|null

Default currency used by Number::currency()

$_formatters ¶

protected static array

A list of number formatters indexed by locale and type

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs