Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

numberformatter(3) [php man page]

NUMBERFORMATTER(3)							 1							NUMBERFORMATTER(3)

The NumberFormatter class

INTRODUCTION
Programs store and operate on numbers using a locale-independent binary representation. When displaying or printing a number it is con- verted 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 speci- fied 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 speci- fied 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: o9 988 776,65 EUR in France o9.988.776,65 EUR in Germany o$9,988,776.65 in the United States 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. CLASS SYNOPSIS
NumberFormatter NumberFormatter Methods o public NumberFormatter::__construct (string $locale, int $style, [string $pattern]) o publicstatic NumberFormatter NumberFormatter::create (string $locale, int $style, [string $pattern]) o public string NumberFormatter::formatCurrency (float $value, string $currency) o public string NumberFormatter::format (number $value, [int $type]) o public int NumberFormatter::getAttribute (int $attr) o public int NumberFormatter::getErrorCode (void ) o public string NumberFormatter::getErrorMessage (void ) o public string NumberFormatter::getLocale ([int $type]) o public string NumberFormatter::getPattern (void ) o public string NumberFormatter::getSymbol (int $attr) o public string NumberFormatter::getTextAttribute (int $attr) o public float NumberFormatter::parseCurrency (string $value, string &$currency, [int &$position]) o public mixed NumberFormatter::parse (string $value, [int $type], [int &$position]) o public bool NumberFormatter::setAttribute (int $attr, int $value) o public bool NumberFormatter::setPattern (string $pattern) o public bool NumberFormatter::setSymbol (int $attr, string $value) o public bool NumberFormatter::setTextAttribute (int $attr, string $value) PREDEFINED CONSTANTS
These styles are used by the numfmt_create(3) to define the type of the formatter. o NumberFormatter::PATTERN_DECIMAL ( integer) -Decimal format defined by pattern o NumberFormatter::DECIMAL ( integer) -Decimal format o NumberFormatter::CURRENCY ( integer) -Currency format o NumberFormatter::PERCENT ( integer) -Percent format o NumberFormatter::SCIENTIFIC ( integer) -Scientific format o NumberFormatter::SPELLOUT ( integer) -Spellout rule-based format o NumberFormatter::ORDINAL ( integer) -Ordinal rule-based format o NumberFormatter::DURATION ( integer) -Duration rule-based format o NumberFormatter::PATTERN_RULEBASED ( integer) -Rule-based format defined by pattern o NumberFormatter::DEFAULT_STYLE ( integer) -Default format for the locale o NumberFormatter::IGNORE ( integer) -Alias for PATTERN_DECIMAL These constants define how the numbers are parsed or formatted. They should be used as arguments to numfmt_format(3) and numfmt_parse(3). o NumberFormatter::TYPE_DEFAULT ( integer) -Derive the type from variable type o NumberFormatter::TYPE_INT32 ( integer) -Format/parse as 32-bit integer o NumberFormatter::TYPE_INT64 ( integer) -Format/parse as 64-bit integer o NumberFormatter::TYPE_DOUBLE ( integer) -Format/parse as floating point value o NumberFormatter::TYPE_CURRENCY ( integer) -Format/parse as currency value Number format attribute used by numfmt_get_attribute(3) and numfmt_set_attribute(3). o NumberFormatter::PARSE_INT_ONLY ( integer) -Parse integers only. o NumberFormatter::GROUPING_USED ( integer) -Use grouping separator. o NumberFormatter::DECIMAL_ALWAYS_SHOWN ( integer) -Always show decimal point. o NumberFormatter::MAX_INTEGER_DIGITS ( integer) -Maximum integer digits. o NumberFormatter::MIN_INTEGER_DIGITS ( integer) -Minimum integer digits. o NumberFormatter::INTEGER_DIGITS ( integer) -Integer digits. o NumberFormatter::MAX_FRACTION_DIGITS ( integer) -Maximum fraction digits. o NumberFormatter::MIN_FRACTION_DIGITS ( integer) -Minimum fraction digits. o NumberFormatter::FRACTION_DIGITS ( integer) -Fraction digits. o NumberFormatter::MULTIPLIER ( integer) -Multiplier. o NumberFormatter::GROUPING_SIZE ( integer) -Grouping size. o NumberFormatter::ROUNDING_MODE ( integer) -Rounding Mode. o NumberFormatter::ROUNDING_INCREMENT ( integer) -Rounding increment. o NumberFormatter::FORMAT_WIDTH ( integer) -The width to which the output of format() is padded. o NumberFormatter::PADDING_POSITION ( integer) - The position at which padding will take place. See pad position constants for pos- sible argument values. o NumberFormatter::SECONDARY_GROUPING_SIZE ( integer) -Secondary grouping size. o NumberFormatter::SIGNIFICANT_DIGITS_USED ( integer) -Use significant digits. o NumberFormatter::MIN_SIGNIFICANT_DIGITS ( integer) -Minimum significant digits. o NumberFormatter::MAX_SIGNIFICANT_DIGITS ( integer) -Maximum significant digits. o NumberFormatter::LENIENT_PARSE ( integer) -Lenient parse mode used by rule-based formats. Number format text attribute used by numfmt_get_text_attribute(3) and numfmt_set_text_attribute(3). o NumberFormatter::POSITIVE_PREFIX ( integer) -Positive prefix. o NumberFormatter::POSITIVE_SUFFIX ( integer) -Positive suffix. o NumberFormatter::NEGATIVE_PREFIX ( integer) -Negative prefix. o NumberFormatter::NEGATIVE_SUFFIX ( integer) -Negative suffix. o NumberFormatter::PADDING_CHARACTER ( integer) -The character used to pad to the format width. o NumberFormatter::CURRENCY_CODE ( integer) -The ISO currency code. o NumberFormatter::DEFAULT_RULESET ( integer) - The default rule set. This is only available with rule-based formatters. o NumberFormatter::PUBLIC_RULESETS ( integer) - The public rule sets. This is only available with rule-based formatters. This is a read-only attribute. The public rulesets are returned as a single string, with each ruleset name delimited by ';' (semicolon). Number format symbols used by numfmt_get_symbol(3) and numfmt_set_symbol(3). o NumberFormatter::DECIMAL_SEPARATOR_SYMBOL ( integer) -The decimal separator. o NumberFormatter::GROUPING_SEPARATOR_SYMBOL ( integer) -The grouping separator. o NumberFormatter::PATTERN_SEPARATOR_SYMBOL ( integer) -The pattern separator. o NumberFormatter::PERCENT_SYMBOL ( integer) -The percent sign. o NumberFormatter::ZERO_DIGIT_SYMBOL ( integer) -Zero. o NumberFormatter::DIGIT_SYMBOL ( integer) -Character representing a digit in the pattern. o NumberFormatter::MINUS_SIGN_SYMBOL ( integer) -The minus sign. o NumberFormatter::PLUS_SIGN_SYMBOL ( integer) -The plus sign. o NumberFormatter::CURRENCY_SYMBOL ( integer) -The currency symbol. o NumberFormatter::INTL_CURRENCY_SYMBOL ( integer) -The international currency symbol. o NumberFormatter::MONETARY_SEPARATOR_SYMBOL ( integer) -The monetary separator. o NumberFormatter::EXPONENTIAL_SYMBOL ( integer) -The exponential symbol. o NumberFormatter::PERMILL_SYMBOL ( integer) -Per mill symbol. o NumberFormatter::PAD_ESCAPE_SYMBOL ( integer) -Escape padding character. o NumberFormatter::INFINITY_SYMBOL ( integer) -Infinity symbol. o NumberFormatter::NAN_SYMBOL ( integer) -Not-a-number symbol. o NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL ( integer) -Significant digit symbol. o NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL ( integer) -The monetary grouping separator. Rounding mode values used by numfmt_get_attribute(3) and numfmt_set_attribute(3) with NumberFormatter::ROUNDING_MODE attribute. o NumberFormatter::ROUND_CEILING ( integer) -Rounding mode to round towards positive infinity. o NumberFormatter::ROUND_DOWN ( integer) -Rounding mode to round towards zero. o NumberFormatter::ROUND_FLOOR ( integer) -Rounding mode to round towards negative infinity. o NumberFormatter::ROUND_HALFDOWN ( integer) - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidis- tant, in which case round down. o NumberFormatter::ROUND_HALFEVEN ( integer) - Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. o NumberFormatter::ROUND_HALFUP ( integer) - Rounding mode to round towards "nearest neighbor" unless both neighbors are equidis- tant, in which case round up. o NumberFormatter::ROUND_UP ( integer) -Rounding mode to round away from zero. Pad position values used by numfmt_get_attribute(3) and numfmt_set_attribute(3) with NumberFormatter::PADDING_POSITION attribute. o NumberFormatter::PAD_AFTER_PREFIX ( integer) -Pad characters inserted after the prefix. o NumberFormatter::PAD_AFTER_SUFFIX ( integer) -Pad characters inserted after the suffix. o NumberFormatter::PAD_BEFORE_PREFIX ( integer) -Pad characters inserted before the prefix. o NumberFormatter::PAD_BEFORE_SUFFIX ( integer) -Pad characters inserted before the suffix. SEE ALSO
o ICU formatting documentation oICU number formatters oICU decimal formatters o ICU rule-based number formatters PHP Documentation Group NUMBERFORMATTER(3)
Man Page