A Library of Helpers for performing simple math operations in Handlebars.
Perform math operations in handlebars. Inspired by this JSFiddle.
Operands are treated as java.math.BigDecimal
and operations are performed with the
java.math.MathContext.DECIMAL64 MathContext
, yielding results with 16 bits of precision
and rounding to the nearest even digit, according to IEEE 754R. You can force rounding
decimal results using the extra parameter scale
, which corresponds to calling
BigDecimal.setScale(int scale, RoundingMode.HALF_UP)
.
{{math arg0 "+" arg1}} // arg0 + arg1
{{math arg0 "-" arg1}} // arg0 - arg1
{{math arg0 "*" arg1}} // arg0 * arg1
{{math arg0 "/" arg1}} // arg0 / arg1
{{math arg0 "%" arg1}} // arg0 % arg1