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
- CNumberFormatter
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
public
|
|
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. |
public
string
|
#
formatCurrency( mixed $value, string $currency, mixed $negativePrefix = null/* x2modend */ )
Formats a number using the currency format defined in the locale. |
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. |
public
string
|
|
protected
string
|
#
formatNumber( array $format, mixed $value )
Formats a number based on a format. This is the method that does actual number formatting. |
protected
array
|