Design

Simple Mathematics

Simple addition, substraction, multiplications, division
COMMUNITY FEATURE Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
  v4.0+ 

With formatters

Here is the list of formatters that can be used to perform simple operations:

Mathematical formula

Formatters add(), mul(), sub() and div() accept simple mathematical expressions inside parenthesis.

Examples:

data
{
  "val"      : 1,
  "otherQty" : 2,
  "vat"      : 0.5,
  "sub"      : {
    "price" : 100
  }
}
template
{d.val:add(.otherQty + .vat * d.sub.price - 10 / 2)}
Carbone Merge Icon
result
48

Arithmetic precision

By default, calculations use double-precision floating-point numbers based on the 64-bit IEEE-754 standard.

To avoid floating-point precision issues, as of version 4.22.4, you can use the option {o.useHighPrecisionArithmetic=true} within a template to enable arbitrary-precision decimal arithmetic for mathematical operations.

When this option is included in the template, the formatters :add, :sub, :mul, :div, :formatC, and :formatN will maintain full decimal precision, up to a maximum of 20 decimal places.