Design
Number Formatting
List of functions to manipulate and transform your JSON numbers
COMMUNITY FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v2.0+
:formatN(precision, options)
UPDATED v5.18.0+
Format number according to the locale.
Applying a number of decimals depends on the report type:
- For ODS/XLSX, the number of decimals has to be formatted based on the text editor.
- For the other types of files, the number of decimals depends on the
precisionparameter passed to the formatter.
The option acc (accounting) writes negative numbers in parentheses, without minus sign.
In XLSX files, the cell is a text with acc. In ODS files, the cell is a number and acc is ignored.
To keep numbers in the cell, use the number format of the cell instead, like #,##0.00;(#,##0.00).
| Params | Description | Type |
|---|---|---|
| precision | Number of decimals | Number |
| options | [optional] acc: negative numbers in parentheses |
String |
Examples
// With API options: {
// "lang": "en-us"
// }
{d.value:formatN()} // input: "10" → output: "10.000"
{d.value:formatN()} // input: "1000.456" → output: "1,000.456"
{d.value:formatN(2, 'acc')} // input: "-1000.456" → output: "(1,000.46)"
:toWord(type, precision, options)
NEW v5.16.0+
Convert a number to words, using the language of the report (options.lang)
Options are keywords, applied only if the language supports them (an unknown keyword throws an error):
feminine(W,O): Spanish, Arabic, Russian, Ukrainian, Polish, Romanian, Croatian, Lithuanian, Latvian, Serbian, Hebrewand(W): English "one hundred and one"noAnd(C): remove "and" between the major and minor unitshundredPairing(W): English "fifteen hundred", French "dix-neuf cents"hyphen(W): French hyphens between all words (1990 spelling)informal(W,O,C): Chinese non-financial numeralsaccusative,genitive(W,O,C): Arabic grammatical case
The type C uses the same currency as :formatC, and converts the amount using the currency rates.
A value which cannot be converted (not a number, out of range, decimal ordinal, ...) is returned unchanged.
Supported languages: https://github.com/forzagreen/n2words/blob/main/LANGUAGES.md
| Params | Description | Type |
|---|---|---|
| type | [optional] Type of conversion: - W : cardinal number "one thousand two hundred thirty-four" (by default) - O : ordinal number "second" - C : amount with currency "twelve euros and fifty cents" |
String |
| precision | [optional] Number of decimals (W: 3 by default, C: precision of the currency). Ignored by O. For C, it throws an error if the precision is greater than the minor unit of the currency (2 for EUR, 0 for JPY). If it is not a number, it is considered as an option. |
Number |
| options | [optional] Keywords, separated by commas | String |
Examples
// With API options: {
// "lang": "fr-fr",
// "currency": {
// "source": "EUR",
// "target": "EUR",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
{d.value:toWord()} // input: 1234 → output: "mille deux cent trente-quatre"
{d.value:toWord()} // input: 1234.5 → output: "mille deux cent trente-quatre virgule cinq"
{d.value:toWord('W', 2)} // input: 3.14159 → output: "trois virgule quatorze"
{d.value:toWord('O')} // input: 2 → output: "deuxième"
{d.value:toWord('C')} // input: 1234.5 → output: "mille deux cent trente-quatre euros et cinquante centimes"
{d.value:toWord('C', 0)} // input: 1234.5 → output: "mille deux cent trente-cinq euros"
{d.value:toWord('W', 0, 'hyphen')} // input: 21 → output: "vingt-et-un"
// With API options: {
// "lang": "es-es",
// "currency": {
// "source": "EUR",
// "target": "EUR",
// "rates": {
// "EUR": 1,
// "USD": 2
// }
// }
// }
{d.value:toWord('W', 0, 'feminine')} // input: 201 → output: "doscientas una"
{d.value:toWord('O', 'feminine')} // input: 2 → output: "segunda"
:round(precision)
v1.2.0+
Round a number
Same as toFixed(2) but it rounds number correclty round(1.05, 1) = 1.1.
Half values are rounded away from zero, like Intl.NumberFormat: round(-1.005, 2) = -1.01
| Params | Description | Type |
|---|---|---|
| precision | number of decimal | Number |
Examples
{d.value:round(2)} // input: 10.05123 → output: 10.05
{d.value:round(1)} // input: 1.05 → output: 1.1
{d.value:round(2)} // input: -1.005 → output: -1.01
:add(value)
v1.2.0+
Add two numbers
| Params | Description | Type |
|---|---|---|
| value | Value to add | Number |
Examples
{d.value:add(2)} // input: 1000.4 → output: 1002.4
{d.value:add('2')} // input: "1000.4" → output: 1002.4
:sub(value)
v1.2.0+
Subtract two numbers
| Params | Description | Type |
|---|---|---|
| value | Value to subtract | Number |
Examples
{d.value:sub(2)} // input: 1000.4 → output: 998.4
{d.value:sub('2')} // input: "1000.4" → output: 998.4
:mul(value)
v1.2.0+
Multiply two numbers
| Params | Description | Type |
|---|---|---|
| value | Value to multiply | Number |
Examples
{d.value:mul(2)} // input: 1000.4 → output: 2000.8
{d.value:mul('2')} // input: "1000.4" → output: 2000.8
:div(value)
v1.2.0+
Divide two numbers
| Params | Description | Type |
|---|---|---|
| value | Value to divide | Number |
Examples
{d.value:div(2)} // input: 1000.4 → output: 500.2
{d.value:div('2')} // input: "1000.4" → output: 500.2
:mod(value)
NEW v4.5.2+
Compute modulo
| Params | Description | Type |
|---|---|---|
| value | Y | Number |
Examples
{d.value:mod(2)} // input: 4 → output: 0
{d.value:mod(2)} // input: 3 → output: 1
:abs
NEW v4.12.0+
Get absolute value
Examples
{d.value:abs()} // input: -10 → output: 10
{d.value:abs()} // input: -10.54 → output: 10.54
{d.value:abs()} // input: 10.54 → output: 10.54
{d.value:abs()} // input: "-200" → output: 200
:ceil
v4.22.8+
Rounds towards closest higher integer number
Examples
{d.value:ceil()} // input: 10.05123 → output: 11
{d.value:ceil()} // input: 1.05 → output: 2
{d.value:ceil()} // input: -1.05 → output: -1
:floor
v4.22.8+
Rounds towards closest lower integer number.
Examples
{d.value:floor()} // input: 10.05123 → output: 10
{d.value:floor()} // input: 1.05 → output: 1
{d.value:floor()} // input: -1.05 → output: -2
:int
UNRECOMMENDED FOR USE v1.0.0+
Converts a number to an INT
:toEN
UNRECOMMENDED FOR USE v1.0.0+
Converts a number with English specifications (decimal separator is '.')
:toFixed
UNRECOMMENDED FOR USE v1.0.0+
Converts a number into string, keeping only
:toFR
UNRECOMMENDED FOR USE v1.0.0+
Converts a number with French specifications (decimal separator is ',')
Get inspired by one of our real-life examples: Planning with subtotals, Gallery of images, Grid Layout or Bank Statement