Class NumberFormat

Description

NumberFormat class.

NumberFormat formats decimal numbers in any locale. The decimal number is formatted according to a particular pattern. These patterns can arise from the NumberFormatInfo object which is culturally sensitive. The NumberFormat class can be instantiated in many ways. E.g.

  1. //create a invariant number formatter.
  2. $formatter = new NumberFormat();
  3.  
  4. //create a number format for the french language locale.
  5. $fr = new NumberFormat('fr');
  6.  
  7. //create a number format base on a NumberFormatInfo instance $numberInfo.
  8. $format = new NumberFormat($numberInfo);

A normal decimal number can also be displayed as a currency or as a percentage. For example

  1. $format->format(1234.5); //Decimal number "1234.5"
  2. $format->format(1234.5,'c'); //Default currency "$1234.50"
  3. $format->format(0.25, 'p')

Currency is formated using the localized currency pattern. For example to format the number as Japanese Yen:

  1. $ja = new NumberFormat('ja_JP');
  2.  
  3. //Japanese currency pattern, and using Japanese Yen symbol
  4. $ja->format(123.14,'c','JPY'); //�?123 (Yen 123)
For each culture, the symbol for each currency may be different.

Located in /I18N/core/NumberFormat.php (line 74)


	
			
Variable Summary
Method Summary
NumberFormat __construct ([mixed $formatInfo = null])
string format (mixed $number, [string $pattern = 'd'], [string $currency = 'USD'], [mixed $charset = 'UTF-8'])
string formatDecimal (string $string)
string formatInteger (string $string)
string setPattern (string $pattern)
Variables
DateTimeFormatInfo $formatInfo (line 81)

The DateTimeFormatInfo, containing culture specific patterns and names.

  • access: protected
Methods
Constructor __construct (line 91)

Create a new number format instance. The constructor can be instantiated with a string that represent a culture/locale. Similarly, passing a CultureInfo or NumberFormatInfo instance will instantiated a instance for that particular culture.

NumberFormat __construct ([mixed $formatInfo = null])
  • mixed $formatInfo: either null, a CultureInfo, a NumberFormatInfo, or string
format (line 116)

For the number for a certain pattern. The valid patterns are 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for 3 decimal places.

  • return: formatted number string
string format (mixed $number, [string $pattern = 'd'], [string $currency = 'USD'], [mixed $charset = 'UTF-8'])
  • mixed $number: the number to format.
  • string $pattern: the format pattern, either, 'c', 'd', 'e', 'p' or a custom pattern. E.g. "#.000" will format the number to 3 decimal places.
  • string $currency: 3-letter ISO 4217 code. For example, the code "USD" represents the US Dollar and "EUR" represents the Euro currency.
formatDecimal (line 229)

Format the decimal places.

  • return: formatted decimal places.
  • access: protected
string formatDecimal (string $string)
  • string $string: the decimal number in string form.
formatInteger (line 159)

For the integer, perform groupings and string padding.

  • return: formatted integer string with grouping
  • access: protected
string formatInteger (string $string)
  • string $string: the decimal number in string form.
setPattern (line 274)

Set the pattern to format against. The default patterns are retrieved from the NumberFormatInfo instance.

  • return: a number format pattern.
  • access: protected
string setPattern (string $pattern)
  • string $pattern: the requested patterns.

Documentation generated on Sun, 04 Jun 2006 18:58:31 -0400 by phpDocumentor 1.3.0RC4