Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CChoiceFormat
  • CDateFormatter
  • CDbMessageSource
  • CGettextMessageSource
  • CLocale
  • CMessageSource
  • CMissingTranslationEvent
  • CNumberFormatter
  • CPhpMessageSource
  • Overview
  • Package
  • Class
  • Tree

Class CNumberFormatter

CNumberFormatter provides number localization functionalities.

CNumberFormatter formats a number (integer or float) and outputs a string based on the specified format. A CNumberFormatter instance is associated with a locale, and thus generates the string representation of the number in a locale-dependent fashion.

CNumberFormatter currently supports currency format, percentage format, decimal format, and custom format. The first three formats are specified in the locale data, while the custom format allows you to enter an arbitrary format string.

A format string may consist of the following special characters:
  • dot (.): the decimal point. It will be replaced with the localized decimal point.
  • comma (,): the grouping separator. It will be replaced with the localized grouping separator.
  • zero (0): required digit. This specifies the places where a digit must appear (will pad 0 if not).
  • hash (#): optional digit. This is mainly used to specify the location of decimal point and grouping separators.
  • currency (¤): the currency placeholder. It will be replaced with the localized currency symbol.
  • percentage (%): the percentage mark. If appearing, the number will be multiplied by 100 before being formatted.
  • permillage (‰): the permillage mark. If appearing, the number will be multiplied by 1000 before being formatted.
  • semicolon (;): the character separating positive and negative number sub-patterns.

Anything surrounding the pattern (or sub-patterns) will be kept.

The followings are some examples:

Pattern "#,##0.00" will format 12345.678 as "12,345.68".
Pattern "#,#,#0.00" will format 12345.6 as "1,2,3,45.60".

Note, in the first example, the number is rounded first before applying the formatting. And in the second example, the pattern specifies two grouping sizes.

CNumberFormatter attempts to implement number formatting according to the Unicode Technical Standard #35. The following features are NOT implemented:
  • significant digit
  • scientific format
  • arbitrary literal characters
  • arbitrary padding
CComponent
Extended by CNumberFormatter
Package: system\i18n
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/i18n/CNumberFormatter.php
Methods summary
public
# __construct( mixed $locale )

Constructor.

Constructor.

Parameters

$locale
mixed
$locale locale ID (string) or CLocale instance
public string
# format( string $pattern, mixed $value, string $currency = null/* x2modstart */, mixed $negativePrefix = null/* x2modend */ )

Formats a number based on the specified pattern. Note, if the format contains '%', the number will be multiplied by 100 first. If the format contains '‰', the number will be multiplied by 1000. If the format contains currency placeholder, it will be replaced by the specified localized currency symbol.

Formats a number based on the specified pattern. Note, if the format contains '%', the number will be multiplied by 100 first. If the format contains '‰', the number will be multiplied by 1000. If the format contains currency placeholder, it will be replaced by the specified localized currency symbol.

Parameters

$pattern
string
$pattern format pattern
$value
mixed
$value the number to be formatted
$currency
string
$currency 3-letter ISO 4217 code. For example, the code "USD" represents the US Dollar and "EUR" represents the Euro currency. The currency placeholder in the pattern will be replaced with the currency symbol. If null, no replacement will be done.
$negativePrefix

Returns

string
the formatting result.
public string
# formatCurrency( mixed $value, string $currency, mixed $negativePrefix = null/* x2modend */ )

Formats a number using the currency format defined in the locale.

Formats a number using the currency format defined in the locale.

Parameters

$value
mixed
$value the number to be formatted
$currency
string
$currency 3-letter ISO 4217 code. For example, the code "USD" represents the US Dollar and "EUR" represents the Euro currency. The currency placeholder in the pattern will be replaced with the currency symbol.
$negativePrefix

Returns

string
the formatting result.
public string
# formatPercentage( mixed $value )

Formats a number using the percentage format defined in the locale. Note, if the percentage format contains '%', the number will be multiplied by 100 first. If the percentage format contains '‰', the number will be multiplied by 1000.

Formats a number using the percentage format defined in the locale. Note, if the percentage format contains '%', the number will be multiplied by 100 first. If the percentage format contains '‰', the number will be multiplied by 1000.

Parameters

$value
mixed
$value the number to be formatted

Returns

string
the formatting result.
public string
# formatDecimal( mixed $value )

Formats a number using the decimal format defined in the locale.

Formats a number using the decimal format defined in the locale.

Parameters

$value
mixed
$value the number to be formatted

Returns

string
the formatting result.
protected string
# formatNumber( array $format, mixed $value )

Formats a number based on a format. This is the method that does actual number formatting.

Formats a number based on a format. This is the method that does actual number formatting.

Parameters

$format
array
$format format with the following structure: <pre> array( // number of required digits after the decimal point, // will be padded with 0 if not enough digits, // -1 means we should drop the decimal point 'decimalDigits'=>2, // maximum number of digits after the decimal point, // additional digits will be truncated. 'maxDecimalDigits'=>3, // number of required digits before the decimal point, // will be padded with 0 if not enough digits 'integerDigits'=>1, // the primary grouping size, 0 means no grouping 'groupSize1'=>3, // the secondary grouping size, 0 means no secondary grouping 'groupSize2'=>0, 'positivePrefix'=>'+', // prefix to positive number 'positiveSuffix'=>'', // suffix to positive number 'negativePrefix'=>'(', // prefix to negative number 'negativeSuffix'=>')', // suffix to negative number 'multiplier'=>1, // 100 for percent, 1000 for per mille ); </pre>
$value
mixed
$value the number to be formatted

Returns

string
the formatted result
protected array
# parseFormat( string $pattern )

Parses a given string pattern.

Parses a given string pattern.

Parameters

$pattern
string
$pattern the pattern to be parsed

Returns

array
the parsed pattern

See

CNumberFormatter::formatNumber()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
API documentation generated by ApiGen 2.8.0