• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Format textview in code?

How do you format a textview?:
Let say I have 4 float variables
x input from user
y input from user
z input from user
a output from program

a = ((x *y) / z);
a = a * 1000;

this works but is not formatted:
TextView.setText(String,valueOf(a));

so if x = 1, y = 2, and z = 12;
a will = 166.666667

I want to be able to format 'a';

I want to be able to format 'TextView.setText(String,valueOf(a)); so 'a' will be displayed as 166.66 or 166.67 as the case may be in a TextView.

or even 166.667 .
 
DecimalFormat df = new DecimalFormat("#0.000");
String fmt = df.format(a);
TextView.setText(fmt)
 
Back
Top Bottom