Am writing an android code where a text view is being populated by a calculated % inside my java class.
As i had to calulate the %, my final variable (calcPerc) is a double type of variable. It wont setText into my TextView.
Please help.
Code
int totDiff = (totalMA - totalIA);
double beforeperc = ((double)totDiff / (double)totalIA);
calPerc = ((double)beforeperc*100);
percentage = (TextView)findViewById(R.id.populatePercentage);
percentage.setText(calPerc);
The error i am getting is
The method setText(CharSequence) in the type TextView is not applicable for the arguments (double)
Also, one more followup question. The variable “calPerc” as it is double, gives me infinite digits after the decimal. How do i round it off to 2 decimals only?
This should format the value for display (with max 2 decimals) correctly for your current locale;