PARSE_CURRENCY PARSE_CURRENCY

PARSE_CURRENCY

Chandra Bergmann Chandra Bergmann

The function PARSE_CURRENCY takes a String and returns a Currency.

This function parses a Currency from a string such as "$1.00". If the input string cannot be parsed into a Currency, PARSE_CURRENCY will return a Currency of zero U.S. dollars and a precision of two, See Working with Numbers and Currency in Airscript for more details.

Declaration

PARSE_CURRENCY(currency_string, locale) -> currency

Parameters

currency_string (required, type: string)
A string representing a currency.
locale (optional, type: string, default: "en-US")
The locale to use when parsing a currency symbol. For example, the string "$1.00" will be parsed as one U.S. dollar given a locale of "en-US", but will be parsed as one Canadian dollar when given a locale of "en-CA".

Return Values

currency (type: currency)
A Currency with an amount/code that is parsed from currency_string, and an appropriate precision for the world currency that was parsed.

Examples

By default, when the locale parameter is omitted, the currency will be parsed using a locale of "en-US".
PARSE_CURRENCY("$1.00") -> {
amount: 100,
code: "USD",
precision: 2
}

With a locale of "en-CA", the dollar sign will be interpreted as Canadian dollars rather than U.S. dollars.

PARSE_CURRENCY("$1.00", "CAD") -> {
amount: 100,
code: "CAD",
precision: 2
}

If there is no currency symbol in the input string, U.S. dollars will be assumed.

PARSE_CURRENCY("1.00", "CAD") -> {
amount: 100,
code: "USD",
precision: 2
}

Regardless of the locale provided, the Euro symbol () will always be interpreted as Euros. The locale will be used only for disambiguation.

PARSE_CURRENCY("€1.00") -> { 
amount: 100,
code: "EUR",
precision: 2
}
PARSE_CURRENCY("€1.00", "en-CA") -> {
amount: 100,
code: "EUR",
precision: 2
}

If a currency cannot be parsed, PARSE_CURRENCY will return a value of zero U.S. dollars.

PARSE_CURRENCY("Not a currency") -> { 
amount: 0,
code: "USD",
precision: 2
}

This is true regardless of the provided locale.

PARSE_CURRENCY("Not a currency", "en-CA") -> {
amount: 0,
code: "USD",
precision: 2
}

Discussion

The PARSE_CURRENCY function is the logical opposite of the FORMAT_CURRENCY function. In most cases, formatting, and then parsing a Currency will return the original value. However, when there is ambiguity as to which world currency a symbol refers to, this may not be the case. For example, formatting, and then parsing Canadian dollars with a locale of "en-US" will return a Currency in U.S. dollars.

PARSE_CURRENCY(FORMAT_CURRENCY(CURRENCY(100, "CAD"))) -> {
amount: 100,
code: "USD",
precision: 2
}

Was this article helpful?

0 out of 0 found this helpful

Articles in this section