(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Programs store and operate on numbers using a locale-independent binary representation. When displaying or printing a number it is converted to a locale-specific string. For example, the number 12345.67 is "12,345.67" in the US, "12 345,67" in France and "12.345,67" in Germany.
By invoking the methods provided by the NumberFormatter class, you can format numbers, currencies, and percentages according to the specified or default locale. NumberFormatter is locale-sensitive so you need to create a new NumberFormatter for each locale. NumberFormatter methods format primitive-type numbers, such as double and output the number as a locale-specific string.
For currencies you can use currency format type to create a formatter that returns a string with the formatted number and the appropriate currency sign. Of course, the NumberFormatter class is unaware of exchange rates so, the number output is the same regardless of the specified currency. This means that the same number has different monetary values depending on the currency locale. If the number is 9988776.65 the results will be:
In order to format percentages, create a locale-specific formatter with percentage format type. With this formatter, a decimal fraction such as 0.75 is displayed as 75%.
For more complex formatting, like spelled-out numbers, the rule-based number formatters are used.
These styles are used by the numfmt_create() to define the type of the formatter.
NumberFormatter::PATTERN_DECIMAL
(integer)
NumberFormatter::DECIMAL
(integer)
NumberFormatter::CURRENCY
(integer)
NumberFormatter::PERCENT
(integer)
NumberFormatter::SCIENTIFIC
(integer)
NumberFormatter::SPELLOUT
(integer)
NumberFormatter::ORDINAL
(integer)
NumberFormatter::DURATION
(integer)
NumberFormatter::PATTERN_RULEBASED
(integer)
NumberFormatter::DEFAULT_STYLE
(integer)
NumberFormatter::IGNORE
(integer)
These constants define how the numbers are parsed or formatted. They should be used as arguments to numfmt_format() and numfmt_parse().
NumberFormatter::TYPE_DEFAULT
(integer)
NumberFormatter::TYPE_INT32
(integer)
NumberFormatter::TYPE_INT64
(integer)
NumberFormatter::TYPE_DOUBLE
(integer)
NumberFormatter::TYPE_CURRENCY
(integer)
Number format attribute used by numfmt_get_attribute() and numfmt_set_attribute().
NumberFormatter::PARSE_INT_ONLY
(integer)
NumberFormatter::GROUPING_USED
(integer)
NumberFormatter::DECIMAL_ALWAYS_SHOWN
(integer)
NumberFormatter::MAX_INTEGER_DIGITS
(integer)
NumberFormatter::MIN_INTEGER_DIGITS
(integer)
NumberFormatter::INTEGER_DIGITS
(integer)
NumberFormatter::MAX_FRACTION_DIGITS
(integer)
NumberFormatter::MIN_FRACTION_DIGITS
(integer)
NumberFormatter::FRACTION_DIGITS
(integer)
NumberFormatter::MULTIPLIER
(integer)
NumberFormatter::GROUPING_SIZE
(integer)
NumberFormatter::ROUNDING_MODE
(integer)
NumberFormatter::ROUNDING_INCREMENT
(integer)
NumberFormatter::FORMAT_WIDTH
(integer)
NumberFormatter::PADDING_POSITION
(integer)
NumberFormatter::SECONDARY_GROUPING_SIZE
(integer)
NumberFormatter::SIGNIFICANT_DIGITS_USED
(integer)
NumberFormatter::MIN_SIGNIFICANT_DIGITS
(integer)
NumberFormatter::MAX_SIGNIFICANT_DIGITS
(integer)
NumberFormatter::LENIENT_PARSE
(integer)
Number format text attribute used by numfmt_get_text_attribute() and numfmt_set_text_attribute().
NumberFormatter::POSITIVE_PREFIX
(integer)
NumberFormatter::POSITIVE_SUFFIX
(integer)
NumberFormatter::NEGATIVE_PREFIX
(integer)
NumberFormatter::NEGATIVE_SUFFIX
(integer)
NumberFormatter::PADDING_CHARACTER
(integer)
NumberFormatter::CURRENCY_CODE
(integer)
NumberFormatter::DEFAULT_RULESET
(integer)
NumberFormatter::PUBLIC_RULESETS
(integer)
Number format symbols used by numfmt_get_symbol() and numfmt_set_symbol().
NumberFormatter::DECIMAL_SEPARATOR_SYMBOL
(integer)
NumberFormatter::GROUPING_SEPARATOR_SYMBOL
(integer)
NumberFormatter::PATTERN_SEPARATOR_SYMBOL
(integer)
NumberFormatter::PERCENT_SYMBOL
(integer)
NumberFormatter::ZERO_DIGIT_SYMBOL
(integer)
NumberFormatter::DIGIT_SYMBOL
(integer)
NumberFormatter::MINUS_SIGN_SYMBOL
(integer)
NumberFormatter::PLUS_SIGN_SYMBOL
(integer)
NumberFormatter::CURRENCY_SYMBOL
(integer)
NumberFormatter::INTL_CURRENCY_SYMBOL
(integer)
NumberFormatter::MONETARY_SEPARATOR_SYMBOL
(integer)
NumberFormatter::EXPONENTIAL_SYMBOL
(integer)
NumberFormatter::PERMILL_SYMBOL
(integer)
NumberFormatter::PAD_ESCAPE_SYMBOL
(integer)
NumberFormatter::INFINITY_SYMBOL
(integer)
NumberFormatter::NAN_SYMBOL
(integer)
NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL
(integer)
NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL
(integer)
Rounding mode values used by numfmt_get_attribute()
and numfmt_set_attribute() with
NumberFormatter::ROUNDING_MODE
attribute.
NumberFormatter::ROUND_CEILING
(integer)
NumberFormatter::ROUND_DOWN
(integer)
NumberFormatter::ROUND_FLOOR
(integer)
NumberFormatter::ROUND_HALFDOWN
(integer)
NumberFormatter::ROUND_HALFEVEN
(integer)
NumberFormatter::ROUND_HALFUP
(integer)
NumberFormatter::ROUND_UP
(integer)
Pad position values used by numfmt_get_attribute()
and numfmt_set_attribute() with
NumberFormatter::PADDING_POSITION
attribute.
NumberFormatter::PAD_AFTER_PREFIX
(integer)
NumberFormatter::PAD_AFTER_SUFFIX
(integer)
NumberFormatter::PAD_BEFORE_PREFIX
(integer)
NumberFormatter::PAD_BEFORE_SUFFIX
(integer)