edu.utexas.tacc.MathHelper Maven / Gradle / Ivy
package edu.utexas.tacc;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.stream.Stream;
/**
* Handlebars Math Helper
*
*
* Perform math operations in handlebars. Inspired by: http://jsfiddle.net/mpetrovich/wMmHS/
* 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)
.
*
*
* addition
*
* {{math arg0 "+" arg1}} // arg0 + arg1
*
* subtraction
*
* {{math arg0 "-" arg1}} // arg0 - arg1
*
* multiplication
*
* {{math arg0 "*" arg1}} // arg0 * arg1
*
* division
*
* {{math arg0 "/" arg1}} // arg0 / arg1
*
* modulus
*
* {{math arg0 "%" arg1}} // arg0 % arg1
*
* @author mrhanlon
* @see java.math.BigDecimal
* @see java.math.MathContext
*/
public class MathHelper implements Helper
© 2015 - 2025 Weber Informatics LLC | Privacy Policy