Back to index

php5  5.3.10
Classes | Functions
formatter_api.php File Reference

Go to the source code of this file.

Classes

class  NumberFormatter
 Number formatter class - locale-dependent number formatting/parsing. More...

Functions

 numfmt_create ($locale, $style, $pattern=null)
 Now the same as procedural API.
 numfmt_format ($formatter, $number, $type=null)
 Format a number according to current formatting rules.
 numfmt_parse ($formatter, $string, $type, &$position)
 Parse a number according to current formatting rules.
 numfmt_format_currency ($formatter, $number, $currency)
 Format number as currency.
 numfmt_parse_currency ($formatter, $string, &$currency, &$position)
 Parse currency string.
 numfmt_set_attribute ($formatter, $attribute, $value)
 Set formatter attribute.
 numfmt_set_text_attribute ($formatter, $attribute, $value)
 Set formatter attribute.
 numfmt_set_symbol ($formatter, $attribute, $value)
 Set formatting symbol.
 numfmt_set_pattern ($formatter, $pattern)
 Set pattern used by the formatter.
 numfmt_get_attribute ($formatter, $attribute)
 Get value of the formatter attribute.
 numfmt_get_text_attribute ($formatter, $attribute)
 Get value of the formatter attribute.
 numfmt_get_symbol ($formatter, $attribute)
 Get value of the formatter symbol.
 numfmt_get_pattern ($formatter)
 Get pattern used by the formatter.
 numfmt_get_locale ($formatter, $type=0)
 Get the locale for which the formatter was created.
 numfmt_get_error_code ($formatter)
 Get the error code from last operation.
 numfmt_get_error_message ($formatter)
 Get the error text from the last operation.

Function Documentation

numfmt_create ( locale,
style,
pattern = null 
)

Now the same as procedural API.

Create a number formatter

Creates a number formatter from locale and pattern. This formatter would be used to format or parse numbers.

Parameters:
string$localeLocale in which the number would be formatted
integer$styleStyle of the formatting, one of the UNumberFormatStyle constants
[string]$pattern Pattern string in case chose style requires pattern
Returns:
Numberformatter resource NumberFormatter

Definition at line 339 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_format ( formatter,
number,
type = null 
)

Format a number according to current formatting rules.

If the type is not specified, the type is derived from the $number parameter. I.e., if it's integer then INT32 would be chosen on 32-bit, INT64 on 64-bit, if it's double, DOUBLE would be chosen. It is possible to format 64-bit number on 32-bit machine by passing it as double and using TYPE_INT64.

Parameters:
NumberFormatter$formatterThe formatter resource
integer | double$numberNumber to format
[integer]$type Type of the formatting - one of TYPE constants. If not specified, default for the type.
Returns:
string formatted number

Definition at line 353 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_format_currency ( formatter,
number,
currency 
)

Format number as currency.

Uses user-defined currency string.

Parameters:
NumberFormatter$formatterThe formatter resource
double$numberNumber to format
string$currency3-letter currency code (ISO 4217) to use in format

Definition at line 376 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_attribute ( formatter,
attribute 
)

Get value of the formatter attribute.

Parameters:
NumberFormatter$formatterThe formatter resource
integer$attributeOne of UNumberFormatAttribute constants
Returns:
integer|double value of the attribute or false if the value can not be obtained

Definition at line 448 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_error_code ( formatter)

Get the error code from last operation.

Returns error code from the last number formatting operation.

Parameters:
NumberFormatter$formatterThe formatter resource
Returns:
integer the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

Definition at line 493 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_error_message ( formatter)

Get the error text from the last operation.

Parameters:
NumberFormatter$formatterThe formatter resource
Returns:
string Description of the last occured error.

Definition at line 500 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_locale ( formatter,
type = 0 
)

Get the locale for which the formatter was created.

Parameters:
NumberFormatter$formatterThe formatter resource
[integer]$type One of ULocDataLocaleType values
Returns:
string locale name

Definition at line 484 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_pattern ( formatter)

Get pattern used by the formatter.

Gets current state of the formatter as a pattern. Localized patterns are not currently supported.

Valid only if the formatter is UNUM_PATTERN_DECIMAL

Parameters:
NumberFormatter$formatterThe formatter resource
Returns:
string|false The pattern used by the formatter or false if formatter is of a type that does not support patterns.

Definition at line 476 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_symbol ( formatter,
attribute 
)

Get value of the formatter symbol.

Parameters:
NumberFormatter$formatterThe formatter resource
integer$attributeOne of UNumberFormatSymbol constants specifying the symbol
Returns:
string|false The symbol value, or false if the value can not be obtained

Definition at line 464 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_get_text_attribute ( formatter,
attribute 
)

Get value of the formatter attribute.

Parameters:
NumberFormatter$formatterThe formatter resource
integer$attributeOne of UNumberFormatTextAttribute constants
Returns:
string value of the attribute or false if the value can not be obtained

Definition at line 456 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_parse ( formatter,
string,
type,
&$  position 
)

Parse a number according to current formatting rules.

This parser uses DOUBLE type by default. When parsing currency, default currency definitions are used.

Parameters:
NumberFormatter$formatterThe formatter resource
string$stringString to parse
[integer]$type Type of the formatting - one of TYPE constants.
[integer]$position String position after the end of parsed data.
Returns:
integer|double|false Parsed number, false if parsing failed

Definition at line 366 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_parse_currency ( formatter,
string,
&$  currency,
&$  position 
)

Parse currency string.

This parser would use parseCurrency API string to parse currency string. The format is defined by the formatter, returns both number and currency code.

Parameters:
NumberFormatter$formatterThe formatter resource
string$stringString to parse
string$currencyParameter to return parsed currency code
[integer]$position String position after the end of parsed data.
Returns:
double currency number

Definition at line 389 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_set_attribute ( formatter,
attribute,
value 
)

Set formatter attribute.

This function is used to set any of the formatter attributes. Example:

numfmt_format_set_attribute($formatter, NumberFormat::FORMAT_WIDTH, 10);

Parameters:
NumberFormatter$formatterThe formatter resource
integer$attrOne of UNumberFormatAttribute constants
integer | double$valueValue of the attribute
Returns:
false if attribute is unknown or can not be set, true otherwise

Definition at line 402 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_set_pattern ( formatter,
pattern 
)

Set pattern used by the formatter.

Valid only if the formatter is using pattern and is not rule-based.

See also:
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html Localized patterns are not currently supported.
Parameters:
NumberFormatter$formatterThe formatter resource
string$patternThe pattern to be used.
Returns:
boolean false if formatter pattern could not be set, true otherwise

Definition at line 440 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_set_symbol ( formatter,
attribute,
value 
)

Set formatting symbol.

Example:

$formatter->setSymbol(NumberFormat::EXPONENTIAL_SYMBOL, "E");

Parameters:
NumberFormatter$formatterThe formatter resource
integer | array$attrOne of UNumberFormatSymbol constants or array of symbols, indexed by these constants
string$valueValue of the symbol

Definition at line 428 of file formatter_api.php.

{}

Here is the caller graph for this function:

numfmt_set_text_attribute ( formatter,
attribute,
value 
)

Set formatter attribute.

This function is used to set any of the formatter attributes. Example:

numfmt_format_set_text_attribute($formatter, NumberFormat::POSITIVE_PREFIX, "+");

Parameters:
NumberFormatter$formatterThe formatter resource
integer$attrOne of UNumberFormatTextAttribute constants
string$valueValue of the attribute
Returns:
false if attribute is unknown or can not be set, true otherwise

Definition at line 415 of file formatter_api.php.

{}

Here is the caller graph for this function: