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)

v1.2.0+

Format number according to the locale.
Applying a number of decimals depends on the report type:

Params Description Type
precision Number of decimals Number

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"

: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):

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

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

: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 decimals

: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