class NumberFormatter

Replacement for PHP's native {@link \NumberFormatter} class.

The only methods currently supported in this class are:

  • {@link __construct}
  • {@link create}
  • {@link formatCurrency}
  • {@link format}
  • {@link getAttribute}
  • {@link getErrorCode}
  • {@link getErrorMessage}
  • {@link getLocale}
  • {@link parse}
  • {@link setAttribute}

Constants

PATTERN_DECIMAL

DECIMAL

CURRENCY

PERCENT

SCIENTIFIC

SPELLOUT

ORDINAL

DURATION

PATTERN_RULEBASED

IGNORE

DEFAULT_STYLE

TYPE_DEFAULT

TYPE_INT32

TYPE_INT64

TYPE_DOUBLE

TYPE_CURRENCY

PARSE_INT_ONLY

GROUPING_USED

DECIMAL_ALWAYS_SHOWN

MAX_INTEGER_DIGITS

MIN_INTEGER_DIGITS

INTEGER_DIGITS

MAX_FRACTION_DIGITS

MIN_FRACTION_DIGITS

FRACTION_DIGITS

MULTIPLIER

GROUPING_SIZE

ROUNDING_MODE

ROUNDING_INCREMENT

FORMAT_WIDTH

PADDING_POSITION

SECONDARY_GROUPING_SIZE

SIGNIFICANT_DIGITS_USED

MIN_SIGNIFICANT_DIGITS

MAX_SIGNIFICANT_DIGITS

LENIENT_PARSE

POSITIVE_PREFIX

POSITIVE_SUFFIX

NEGATIVE_PREFIX

NEGATIVE_SUFFIX

PADDING_CHARACTER

CURRENCY_CODE

DEFAULT_RULESET

PUBLIC_RULESETS

DECIMAL_SEPARATOR_SYMBOL

GROUPING_SEPARATOR_SYMBOL

PATTERN_SEPARATOR_SYMBOL

PERCENT_SYMBOL

ZERO_DIGIT_SYMBOL

DIGIT_SYMBOL

MINUS_SIGN_SYMBOL

PLUS_SIGN_SYMBOL

CURRENCY_SYMBOL

INTL_CURRENCY_SYMBOL

MONETARY_SEPARATOR_SYMBOL

EXPONENTIAL_SYMBOL

PERMILL_SYMBOL

PAD_ESCAPE_SYMBOL

INFINITY_SYMBOL

NAN_SYMBOL

SIGNIFICANT_DIGIT_SYMBOL

MONETARY_GROUPING_SEPARATOR_SYMBOL

ROUND_CEILING

ROUND_FLOOR

ROUND_DOWN

ROUND_UP

ROUND_HALFEVEN

ROUND_HALFDOWN

ROUND_HALFUP

PAD_BEFORE_PREFIX

PAD_AFTER_PREFIX

PAD_BEFORE_SUFFIX

PAD_AFTER_SUFFIX

Methods

__construct(string $locale = 'en', int $style = null, string $pattern = null)

Constructor.

static NumberFormatter
create(string $locale = 'en', int $style = null, string $pattern = null)

Static constructor.

string
formatCurrency(float $value, string $currency)

Format a currency value

Boolean|string
format(number $value, int $type = self::TYPE_DEFAULT)

Format a number

Boolean|int
getAttribute(int $attr)

Returns an attribute value

int
getErrorCode()

Returns formatter's last error code. Always returns the UZEROERROR class constant value

string
getErrorMessage()

Returns formatter's last error message. Always returns the UZEROERROR_MESSAGE class constant value

string
getLocale(int $type = Locale::ACTUAL_LOCALE)

Returns the formatter's locale

Boolean|string
getPattern()

Not supported. Returns the formatter's pattern

Boolean|string
getSymbol(int $attr)

Not supported. Returns a formatter symbol value

Boolean|string
getTextAttribute(int $attr)

Not supported. Returns a formatter text attribute value

Boolean|string
parseCurrency(string $value, string $currency, int $position = null)

Not supported. Parse a currency number

Boolean|string
parse(string $value, string $type = self::TYPE_DOUBLE, int $position)

Parse a number

Boolean
setAttribute(int $attr, int $value)

Set an attribute

Boolean
setPattern(string $pattern)

Not supported. Set the formatter's pattern

Boolean
setSymbol(int $attr, string $value)

Not supported. Set the formatter's symbol

Boolean
setTextAttribute(int $attr, int $value)

Not supported. Set a text attribute

Details

at line line 264
__construct(string $locale = 'en', int $style = null, string $pattern = null)

Constructor.

Parameters

string $locale The locale code. The only currently supported locale is "en".
int $style Style of the formatting, one of the format style constants. The only supported styles are NumberFormatter::DECIMAL and NumberFormatter::CURRENCY.
string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERNDECIMAL or NumberFormat::PATTERNRULEBASED. It must conform to the syntax described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation

Exceptions

MethodArgumentValueNotImplementedException When $locale different than "en" is passed
MethodArgumentValueNotImplementedException When the $style is not supported
MethodArgumentNotImplementedException When the pattern value is different than null

See also

http://www.php.net/manual/en/numberformatter.create.php
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details

at line line 303
static NumberFormatter create(string $locale = 'en', int $style = null, string $pattern = null)

Static constructor.

Parameters

string $locale The locale code. The only supported locale is "en".
int $style Style of the formatting, one of the format style constants. The only currently supported styles are NumberFormatter::DECIMAL and NumberFormatter::CURRENCY.
string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERNDECIMAL or NumberFormat::PATTERNRULEBASED. It must conform to the syntax described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation

Return Value

NumberFormatter

Exceptions

MethodArgumentValueNotImplementedException When $locale different than "en" is passed
MethodArgumentValueNotImplementedException When the $style is not supported
MethodArgumentNotImplementedException When the pattern value is different than null

See also

http://www.php.net/manual/en/numberformatter.create.php
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details

at line line 319
string formatCurrency(float $value, string $currency)

Format a currency value

Parameters

float $value The numeric currency value
string $currency The 3-letter ISO 4217 currency code indicating the currency to use

Return Value

string The formatted currency value

See also

http://www.php.net/manual/en/numberformatter.formatcurrency.php
http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/currency_codes/currency_codes_list-1.htm

at line line 357
Boolean|string format(number $value, int $type = self::TYPE_DEFAULT)

Format a number

Parameters

number $value The value to format
int $type Type of the formatting, one of the format type constants. Only type NumberFormatter::TYPE_DEFAULT is currently supported.

Return Value

Boolean|string The formatted value or false on error

Exceptions

NotImplementedException If the method is called with the class $style 'CURRENCY'
MethodArgumentValueNotImplementedException If the $type is different than TYPE_DEFAULT

See also

http://www.php.net/manual/en/numberformatter.format.php

at line line 398
Boolean|int getAttribute(int $attr)

Returns an attribute value

Parameters

int $attr An attribute specifier, one of the numeric attribute constants

Return Value

Boolean|int The attribute value on success or false on error

See also

http://www.php.net/manual/en/numberformatter.getattribute.php

at line line 410
int getErrorCode()

Returns formatter's last error code. Always returns the UZEROERROR class constant value

Return Value

int The error code from last formatter call

See also

http://www.php.net/manual/en/numberformatter.geterrorcode.php

at line line 422
string getErrorMessage()

Returns formatter's last error message. Always returns the UZEROERROR_MESSAGE class constant value

Return Value

string The error message from last formatter call

See also

http://www.php.net/manual/en/numberformatter.geterrormessage.php

at line line 439
string getLocale(int $type = Locale::ACTUAL_LOCALE)

Returns the formatter's locale

The parameter $type is currently ignored.

Parameters

int $type Not supported. The locale name type to return (Locale::VALIDLOCALE or Locale::ACTUALLOCALE)

Return Value

string The locale used to create the formatter. Currently always returns "en".

See also

http://www.php.net/manual/en/numberformatter.getlocale.php

at line line 453
Boolean|string getPattern()

Not supported. Returns the formatter's pattern

Return Value

Boolean|string The pattern string used by the formatter or false on error

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/numberformatter.getpattern.php

at line line 467
Boolean|string getSymbol(int $attr)

Not supported. Returns a formatter symbol value

Parameters

int $attr A symbol specifier, one of the format symbol constants

Return Value

Boolean|string The symbol value or false on error

See also

http://www.php.net/manual/en/numberformatter.getsymbol.php

at line line 481
Boolean|string getTextAttribute(int $attr)

Not supported. Returns a formatter text attribute value

Parameters

int $attr An attribute specifier, one of the text attribute constants

Return Value

Boolean|string The attribute value or false on error

See also

http://www.php.net/manual/en/numberformatter.gettextattribute.php

at line line 499
Boolean|string parseCurrency(string $value, string $currency, int $position = null)

Not supported. Parse a currency number

Parameters

string $value The value to parse
string $currency Parameter to receive the currency name (reference)
int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended

Return Value

Boolean|string The parsed numeric value of false on error

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/numberformatter.parsecurrency.php

at line line 515
Boolean|string parse(string $value, string $type = self::TYPE_DOUBLE, int $position)

Parse a number

Parameters

string $value The value to parse
string $type Type of the formatting, one of the format type constants. NumberFormatter::TYPE_DOUBLE by default
int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended

Return Value

Boolean|string The parsed value of false on error

See also

http://www.php.net/manual/en/numberformatter.parse.php

at line line 563
Boolean setAttribute(int $attr, int $value)

Set an attribute

Parameters

int $attr An attribute specifier, one of the numeric attribute constants. The only currently supported attributes are NumberFormatter::FRACTIONDIGITS, NumberFormatter::GROUPINGUSED and NumberFormatter::ROUNDING_MODE.
int $value The attribute value. The only currently supported rounding modes are NumberFormatter::ROUNDHALFEVEN, NumberFormatter::ROUNDHALFDOWN and NumberFormatter::ROUND_HALFUP.

Return Value

Boolean true on success or false on failure

Exceptions

MethodArgumentValueNotImplementedException When the $attr is not supported
MethodArgumentValueNotImplementedException When the $value is not supported

See also

http://www.php.net/manual/en/numberformatter.setattribute.php

at line line 609
Boolean setPattern(string $pattern)

Not supported. Set the formatter's pattern

Parameters

string $pattern A pattern string in conformance with the ICU DecimalFormat documentation

Return Value

Boolean true on success or false on failure

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/numberformatter.setpattern.php
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details

at line line 626
Boolean setSymbol(int $attr, string $value)

Not supported. Set the formatter's symbol

Parameters

int $attr A symbol specifier, one of the format symbol constants
string $value The value for the symbol

Return Value

Boolean true on success or false on failure

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/numberformatter.setsymbol.php

at line line 643
Boolean setTextAttribute(int $attr, int $value)

Not supported. Set a text attribute

Parameters

int $attr An attribute specifier, one of the text attribute constants
int $value The attribute value

Return Value

Boolean true on success or false on failure

Exceptions

MethodNotImplementedException

See also

http://www.php.net/manual/en/numberformatter.settextattribute.php