Symfony\Component\Intl\NumberFormatter\NumberFormatter
Replacement for PHP's native {@link \NumberFormatter} class.
The only methods currently supported in this class are:
- - - - - - - - - -
- Author: Eriksen Costa <eriksen.costa@infranology.com.br>
Synopsis
class NumberFormatter
{
- // constants
- const PATTERN_DECIMAL = 0;
- const DECIMAL = 1;
- const CURRENCY = 2;
- const PERCENT = 3;
- const SCIENTIFIC = 4;
- const SPELLOUT = 5;
- const ORDINAL = 6;
- const DURATION = 7;
- const PATTERN_RULEBASED = 9;
- const IGNORE = 0;
- const DEFAULT_STYLE = 1;
- const TYPE_DEFAULT = 0;
- const TYPE_INT32 = 1;
- const TYPE_INT64 = 2;
- const TYPE_DOUBLE = 3;
- const TYPE_CURRENCY = 4;
- const PARSE_INT_ONLY = 0;
- const GROUPING_USED = 1;
- const DECIMAL_ALWAYS_SHOWN = 2;
- const MAX_INTEGER_DIGITS = 3;
- const MIN_INTEGER_DIGITS = 4;
- const INTEGER_DIGITS = 5;
- const MAX_FRACTION_DIGITS = 6;
- const MIN_FRACTION_DIGITS = 7;
- const FRACTION_DIGITS = 8;
- const MULTIPLIER = 9;
- const GROUPING_SIZE = 10;
- const ROUNDING_MODE = 11;
- const ROUNDING_INCREMENT = 12;
- const FORMAT_WIDTH = 13;
- const PADDING_POSITION = 14;
- const SECONDARY_GROUPING_SIZE = 15;
- const SIGNIFICANT_DIGITS_USED = 16;
- const MIN_SIGNIFICANT_DIGITS = 17;
- const MAX_SIGNIFICANT_DIGITS = 18;
- const LENIENT_PARSE = 19;
- const POSITIVE_PREFIX = 0;
- const POSITIVE_SUFFIX = 1;
- const NEGATIVE_PREFIX = 2;
- const NEGATIVE_SUFFIX = 3;
- const PADDING_CHARACTER = 4;
- const CURRENCY_CODE = 5;
- const DEFAULT_RULESET = 6;
- const PUBLIC_RULESETS = 7;
- const DECIMAL_SEPARATOR_SYMBOL = 0;
- const GROUPING_SEPARATOR_SYMBOL = 1;
- const PATTERN_SEPARATOR_SYMBOL = 2;
- const PERCENT_SYMBOL = 3;
- const ZERO_DIGIT_SYMBOL = 4;
- const DIGIT_SYMBOL = 5;
- const MINUS_SIGN_SYMBOL = 6;
- const PLUS_SIGN_SYMBOL = 7;
- const CURRENCY_SYMBOL = 8;
- const INTL_CURRENCY_SYMBOL = 9;
- const MONETARY_SEPARATOR_SYMBOL = 10;
- const EXPONENTIAL_SYMBOL = 11;
- const PERMILL_SYMBOL = 12;
- const PAD_ESCAPE_SYMBOL = 13;
- const INFINITY_SYMBOL = 14;
- const NAN_SYMBOL = 15;
- const SIGNIFICANT_DIGIT_SYMBOL = 16;
- const MONETARY_GROUPING_SEPARATOR_SYMBOL = 17;
- const ROUND_CEILING = 0;
- const ROUND_FLOOR = 1;
- const ROUND_DOWN = 2;
- const ROUND_UP = 3;
- const ROUND_HALFEVEN = 4;
- const ROUND_HALFDOWN = 5;
- const ROUND_HALFUP = 6;
- const PAD_BEFORE_PREFIX = 0;
- const PAD_AFTER_PREFIX = 1;
- const PAD_BEFORE_SUFFIX = 2;
- const PAD_AFTER_SUFFIX = 3;
- // members
- protected integer $errorCode;
- protected string $errorMessage;
- private int $style;
- private array $attributes;
- private array $initializedAttributes;
- private array $supportedStyles;
- private array $supportedAttributes;
- private array $roundingModes;
- private array $phpRoundingMap;
- private array $int32Range;
- private array $int64Range;
- // methods
- public void __construct()
- public static NumberFormatter create()
- public string formatCurrency()
- public Boolean|string format()
- public Boolean|int getAttribute()
- public int getErrorCode()
- public string getErrorMessage()
- public string getLocale()
- public Boolean|string getPattern()
- public Boolean|string getSymbol()
- public Boolean|string getTextAttribute()
- public Boolean|string parseCurrency()
- public Boolean|string parse()
- public Boolean setAttribute()
- public Boolean setPattern()
- public Boolean setSymbol()
- public Boolean setTextAttribute()
- protected void resetError()
- private string roundCurrency()
- private integer|float round()
- private string formatNumber()
- private int getUnitializedPrecision()
- private Boolean isInitializedAttribute()
- private integer|float convertValueDataType()
- private int getInt32Value()
- private int|float getInt64Value()
- private Boolean isInvalidRoundingMode()
- private int normalizeGroupingUsedValue()
- private int normalizeFractionDigitsValue()
Hierarchy
Constants
Name | Value |
---|---|
PATTERN_DECIMAL | 0 |
DECIMAL | 1 |
CURRENCY | 2 |
PERCENT | 3 |
SCIENTIFIC | 4 |
SPELLOUT | 5 |
ORDINAL | 6 |
DURATION | 7 |
PATTERN_RULEBASED | 9 |
IGNORE | 0 |
DEFAULT_STYLE | 1 |
TYPE_DEFAULT | 0 |
TYPE_INT32 | 1 |
TYPE_INT64 | 2 |
TYPE_DOUBLE | 3 |
TYPE_CURRENCY | 4 |
PARSE_INT_ONLY | 0 |
GROUPING_USED | 1 |
DECIMAL_ALWAYS_SHOWN | 2 |
MAX_INTEGER_DIGITS | 3 |
MIN_INTEGER_DIGITS | 4 |
INTEGER_DIGITS | 5 |
MAX_FRACTION_DIGITS | 6 |
MIN_FRACTION_DIGITS | 7 |
FRACTION_DIGITS | 8 |
MULTIPLIER | 9 |
GROUPING_SIZE | 10 |
ROUNDING_MODE | 11 |
ROUNDING_INCREMENT | 12 |
FORMAT_WIDTH | 13 |
PADDING_POSITION | 14 |
SECONDARY_GROUPING_SIZE | 15 |
SIGNIFICANT_DIGITS_USED | 16 |
MIN_SIGNIFICANT_DIGITS | 17 |
MAX_SIGNIFICANT_DIGITS | 18 |
LENIENT_PARSE | 19 |
POSITIVE_PREFIX | 0 |
POSITIVE_SUFFIX | 1 |
NEGATIVE_PREFIX | 2 |
NEGATIVE_SUFFIX | 3 |
PADDING_CHARACTER | 4 |
CURRENCY_CODE | 5 |
DEFAULT_RULESET | 6 |
PUBLIC_RULESETS | 7 |
DECIMAL_SEPARATOR_SYMBOL | 0 |
GROUPING_SEPARATOR_SYMBOL | 1 |
PATTERN_SEPARATOR_SYMBOL | 2 |
PERCENT_SYMBOL | 3 |
ZERO_DIGIT_SYMBOL | 4 |
DIGIT_SYMBOL | 5 |
MINUS_SIGN_SYMBOL | 6 |
PLUS_SIGN_SYMBOL | 7 |
CURRENCY_SYMBOL | 8 |
INTL_CURRENCY_SYMBOL | 9 |
MONETARY_SEPARATOR_SYMBOL | 10 |
EXPONENTIAL_SYMBOL | 11 |
PERMILL_SYMBOL | 12 |
PAD_ESCAPE_SYMBOL | 13 |
INFINITY_SYMBOL | 14 |
NAN_SYMBOL | 15 |
SIGNIFICANT_DIGIT_SYMBOL | 16 |
MONETARY_GROUPING_SEPARATOR_SYMBOL | 17 |
ROUND_CEILING | 0 |
ROUND_FLOOR | 1 |
ROUND_DOWN | 2 |
ROUND_UP | 3 |
ROUND_HALFEVEN | 4 |
ROUND_HALFDOWN | 5 |
ROUND_HALFUP | 6 |
PAD_BEFORE_PREFIX | 0 |
PAD_AFTER_PREFIX | 1 |
PAD_BEFORE_SUFFIX | 2 |
PAD_AFTER_SUFFIX | 3 |
Members
private
- $attributes
—
array
Default values for the en locale - $initializedAttributes
—
array
Holds the initialized attributes code - $int32Range
—
array
The maximum values of the integer type in 32 bit platforms. - $int64Range
—
array
The maximum values of the integer type in 64 bit platforms. - $phpRoundingMap
—
array
The mapping between NumberFormatter rounding modes to the available modes in PHP's round() function. - $roundingModes
—
array
The available rounding modes for setAttribute() usage with NumberFormatter::ROUNDING_MODE. NumberFormatter::ROUND_DOWN and NumberFormatter::ROUND_UP does not have a PHP only equivalent - $style — int
- $supportedAttributes
—
array
Supported attributes to the setAttribute() $attr argument - $supportedStyles
—
array
The supported styles to the constructor $styles argument
protected
- $errorCode
—
integer
The error code from the last operation - $errorMessage
—
string
The error message from the last operation
Methods
private
- convertValueDataType() — Returns the numeric value using the $type to convert to the right data type.
- formatNumber() — Formats a number.
- getInt32Value() — Convert the value data type to int or returns false if the value is out of the integer value range.
- getInt64Value() — Convert the value data type to int or returns false if the value is out of the integer value range.
- getUnitializedPrecision() — Returns the precision value if the DECIMAL style is being used and the FRACTION_DIGITS attribute is unitialized.
- isInitializedAttribute() — Check if the attribute is initialized (value set by client code).
- isInvalidRoundingMode() — Check if the rounding mode is invalid.
- normalizeFractionDigitsValue() — Returns the normalized value for the FRACTION_DIGITS attribute. The value is converted to int and if negative, the returned value will be 0.
- normalizeGroupingUsedValue() — Returns the normalized value for the GROUPING_USED attribute. Any value that can be converted to int will be cast to Boolean and then to int again. This way, negative values are converted to 1 and string values to 0.
- round() — Rounds a value.
- roundCurrency() — Rounds a currency value, applying increment rounding if applicable
protected
- resetError() — Set the error to the default U_ZERO_ERROR
public
- __construct() — Constructor.
- create() — Static constructor.
- format() — Format a number
- formatCurrency() — Format a currency value
- getAttribute() — Returns an attribute value
- getErrorCode() — Returns formatter's last error code. Always returns the U_ZERO_ERROR class constant value
- getErrorMessage() — Returns formatter's last error message. Always returns the U_ZERO_ERROR_MESSAGE class constant value
- getLocale() — Returns the formatter's locale
- getPattern() — Not supported. Returns the formatter's pattern
- getSymbol() — Not supported. Returns a formatter symbol value
- getTextAttribute() — Not supported. Returns a formatter text attribute value
- parse() — Parse a number
- parseCurrency() — Not supported. Parse a currency number
- setAttribute() — Set an attribute
- setPattern() — Not supported. Set the formatter's pattern
- setSymbol() — Not supported. Set the formatter's symbol
- setTextAttribute() — Not supported. Set a text attribute