The CurrencyFormatter class formats a valid number as a currency value.
It adjusts the decimal rounding and precision, the thousands separator,
and the negative sign; it also adds a currency symbol.
You place the currency symbol on either the left or the right side
of the value with the alignSymbol
property.
The currency symbol can contain multiple characters,
including blank spaces.
If an error occurs, an empty String is returned and a String that describes
the error is saved to the error
property. The error
property can have one of the following values:
"Invalid value"
means an invalid numeric value is passed to theformat()
method. The value should be a valid number in the form of a Number or a String."Invalid format"
means one of the parameters contains an unusable setting.
See also:
Constructor
Variables
alignSymbol:String
Aligns currency symbol to the left side or the right side
of the formatted number.
Permitted values are "left"
and "right"
.
See also:
currencySymbol:String
Character to use as a currency symbol for a formatted number. You can use one or more characters to represent the currency symbol; for example, "$" or "YEN". You can also use empty spaces to add space between the currency character and the formatted number. When the number is a negative value, the currency symbol appears between the number and the minus sign or parentheses.
decimalSeparatorTo:String
Decimal separator character to use when outputting formatted decimal numbers.
precision:Int
Number of decimal places to include in the output String.
You can disable precision by setting it to -1
.
A value of -1
means do not change the precision. For example,
if the input value is 1.453 and rounding
is set to NumberBaseRoundType.NONE
, return 1.453.
If precision
is -1 and you set some form of
rounding, return a value based on that rounding type.
rounding:String
Specifies how to round the number.
In Haxe, you can use the following constants to set this property:
See also:
useNegativeSign:Bool
If true
, format a negative number
by preceding it with a minus "-" sign.
If false
, format the number
surrounded by parentheses, for example (400).
useThousandsSeparator:Bool
If true
, split the number into thousands increments
by using a separator character.
Methods
format(value:Dynamic):String
Formats value
as currency.
If value
cannot be formatted, return an empty String
and write a description of the error to the error
property.
Parameters:
value | Value to format. |
---|
Returns:
Formatted string. Empty if an error occurs.