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;
}
}
Aggregations