Search in sources :

Example 1 with ExpressionBuilder

use of de.congrace.exp4j.ExpressionBuilder in project KeepScore by nolanlawson.

the class DialogHelper method doCalculation.

private static boolean doCalculation(EditText field) {
    try {
        Calculable calc = new ExpressionBuilder(field.getText().toString()).build();
        Double val = calc.calculate();
        val = Math.ceil(val);
        String fmtVal = new DecimalFormat("#").format(val);
        field.setText(fmtVal);
        field.setSelection(fmtVal.length());
        return true;
    } catch (Exception ex) {
        Toast.makeText(field.getContext(), R.string.toast_calc_error, Toast.LENGTH_SHORT).show();
        return false;
    }
}
Also used : Calculable(de.congrace.exp4j.Calculable) DecimalFormat(java.text.DecimalFormat) ExpressionBuilder(de.congrace.exp4j.ExpressionBuilder)

Aggregations

Calculable (de.congrace.exp4j.Calculable)1 ExpressionBuilder (de.congrace.exp4j.ExpressionBuilder)1 DecimalFormat (java.text.DecimalFormat)1