All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.praegus.fitnesse.slim.fixtures.util.Calculator Maven / Gradle / Ivy

There is a newer version: 1.38.1
Show newest version
package nl.praegus.fitnesse.slim.fixtures.util;

import org.mariuszgromada.math.mxparser.Expression;

import java.text.DecimalFormat;

public class Calculator {

    private Integer precision;

    public Calculator(int precision) {
        this.precision = precision;
    }

    public Calculator() {
    }

    public String calculate(String input) {
        StringBuilder df = new StringBuilder("#");
        Expression e = new Expression(input);
        double result = e.calculate();
        if (null != precision) {
            df.append(".");
            for(int i = 0; i < precision; i++) {
                df.append("#");
            }
        }
        return new DecimalFormat(df.toString()).format(result).replace(",", ".");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy