Design
Currency Formatting
List of function to manipulate and transform your JSON prices
COMMUNITY FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v2.0+
:formatC(precisionOrFormat, targetCurrency)
v1.2.0+
Params | Description | Type |
---|---|---|
precisionOrFormat | [optional] Number of decimal, or specific format - Integer : change default precision of the currency - M : print Major currency name without the number - L : prints number with currency symbol (by default) - LL : prints number with Major currency name |
Number |
targetCurrency | [optional] target currency code (upper case). Ex: USD, EUR, ... It overwrites the global option options.currencyTarget |
String |
Examples
// With API options: {
// "lang": "en-us",
// "currency": {
// "source": "EUR",
// "target": "USD",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
'1000.456':formatC() // "$2,000.91"
'1000.456':formatC('M') // "dollars"
'1':formatC('M') // "dollar"
'1000':formatC('L') // "$2,000.00"
'1000':formatC('LL') // "2,000.00 dollars"
// With API options: {
// "lang": "fr-fr",
// "currency": {
// "source": "EUR",
// "target": "USD",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
'1000.456':formatC() // "2 000,91 --TMPL-6-MARK--quot;
// With API options: {
// "lang": "fr-fr",
// "currency": {
// "source": "EUR",
// "target": "EUR",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
'1000.456':formatC() // "1 000,46 €"
:convCurr(target, source)
v1.2.0+
Convert from one currency to another
Exchange rates are included by default in Carbone but you can provide a new echange rate
for one report in options.currencyRates
of Carbone.render
or globally with Carbone.set
convCurr()
without parameters converts automatically from options.currencySource
to options.currencyTarget
.
If options.currencySource
is undefined, no conversion will be performed.
Params | Description | Type |
---|---|---|
target | [optional] convert to this currency ('EUR'). By default it equals options.currencyTarget |
String |
source | [optional] currency of source data ('USD'). By default it equals options.currencySource |
String |
Examples
// With API options: {
// "currency": {
// "source": "EUR",
// "target": "USD",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
10:convCurr() // 20
1000:convCurr() // 2000
1000:convCurr('EUR') // 1000
1000:convCurr('USD') // 2000
1000:convCurr('USD', 'USD') // 1000