Design

Number Formatting

List of function 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"
// }
'10':formatN() // "10.000"
'1000.456':formatN() // "1,000.456"

: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

10.05123:round(2) // 10.05
1.05:round(1) // 1.1

:add(value)

v1.2.0+

Add two numbers

Params Description Type
value Value to add Number

Examples

1000.4:add(2) // 1002.4
'1000.4':add('2') // 1002.4

:sub(value)

v1.2.0+

Substract two numbers

Params Description Type
value Value to substract Number

Examples

1000.4:sub(2) // 998.4
'1000.4':sub('2') // 998.4

:mul(value)

v1.2.0+

Multiply two numbers

Params Description Type
value Value to multiply Number

Examples

1000.4:mul(2) // 2000.8
'1000.4':mul('2') // 2000.8

:div(value)

v1.2.0+

Divide two numbers

Params Description Type
value Value to divide Number

Examples

1000.4:div(2) // 500.2
'1000.4':div('2') // 500.2

:mod(value)

NEW v4.5.2+

Compute modulo

Params Description Type
value Y Number

Examples

4:mod(2) // 0
3:mod(2) // 1

:abs

NEW v4.12.0+

Get absolute value

Examples

-10:abs() // 10
-10.54:abs() // 10.54
10.54:abs() // 10.54
'-200':abs() // 200

:ceil

v4.22.8+

Rounds towards closest higher integer number

Examples

10.05123:ceil() // 11
1.05:ceil() // 2
-1.05:ceil() // -1

:floor

v4.22.8+

Rounds towards closest lower integer number.

Examples

10.05123:floor() // 10
1.05:floor() // 1
-1.05:floor() // -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 ',')