1. Download our Official Android App: Forums for Android!

Apps Format textview in code?

Discussion in 'Android Development' started by androidkeep, Apr 28, 2012.

  1. androidkeep

    androidkeep Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Apr 21, 2012

    Apr 21, 2012
    5
    0
    5
    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 .
     

    Advertisement

  2. wubbzy

    wubbzy Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    109
    Joined:
    Dec 19, 2011

    Dec 19, 2011
    109
    32
    63
    *nix kernel's by day
    Silicon Valley
    DecimalFormat df = new DecimalFormat("#0.000");
    String fmt = df.format(a);
    TextView.setText(fmt)
     

Share This Page

Loading...