1

i was made this method to show value of int into text view

    texton= (TextView)findViewById(R.id.textcolumn);
    texton.setText(String.valueOf(score));

so it will show like this

enter image description here

but i want to make the number text format like this, it is possible?

enter image description here

Ricci
  • 217
  • 5
  • 21

3 Answers3

1

You can use DecimalFormat .

public class DecimalFormat extends NumberFormat

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized.

Please have a look here

  1. NumberFormat
  2. How can I format a String number to have commas and round?

So Try this way ,

DecimalFormat formatter = new DecimalFormat("#,###.000");
String get_value = formatter.format(score);
texton= (TextView)findViewById(R.id.textcolumn);
texton.setText(get_value);

Logic Courtesy

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You can use DecimalFormat before setting the value in textView

 texton.setText(setDotsDigit(score));

 public static String setDotsDigit(double value)
{
    return new DecimalFormat("###.###.###").format(value);
}
bond007
  • 2,434
  • 1
  • 17
  • 17
0

You should use DecimalFormat to format your score value first.

DecimalFormat formatter = new DecimalFormat("#,###.00")`;
String s = formatter.format(score);
texton = (TextView)findViewById(R.id.textcolumn);
texton.setText(s);

Hope it will help you.

Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116