java - Android calculator number rounding -
this question has answer here:
- how round number n decimal places in java 28 answers
so calculator gives me answer 30.122345353 or that.
question how can round 30.122 ? here part of code. need round answer comes (ans + "")
this code
if (v.getid() == r.id.badd) if (num2 == 0) flag = true; else ans = 2 * num1; tv2.settext(ans + "");
easy way rounding double int:
int result = ((int)(yourdouble+0.5));
or:
public double roundmyvalue(string value){ decimalformat df=new decimalformat("0.000"); return (double)df.parse(df.format(value)) ; }
or easy:
public double roundmyvalue(string value){ double current=double.parsedouble(value); int temp = current*1000; return (double)temp/1000; }
Comments
Post a Comment