Java 如何设置文本编号格式?

Java 如何设置文本编号格式?,java,android,text,Java,Android,Text,我使用这个方法是为了在文本视图中显示int的值 texton= (TextView)findViewById(R.id.textcolumn); texton.setText(String.valueOf(score)); 所以它会像这样表现出来 但是我想让数字文本格式像这样,有可能吗 在文本视图中设置值之前,可以使用DecimalFormat texton.setText(setDotsDigit(score)); public static String setDo

我使用这个方法是为了在文本视图中显示int的值

    texton= (TextView)findViewById(R.id.textcolumn);
    texton.setText(String.valueOf(score));
所以它会像这样表现出来

但是我想让数字文本格式像这样,有可能吗


在文本视图中设置值之前,可以使用DecimalFormat

 texton.setText(setDotsDigit(score));

 public static String setDotsDigit(double value)
{
    return new DecimalFormat("###.###.###").format(value);
}

您应该首先使用DecimalFormat格式化您的
分数

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

希望它能对您有所帮助。

您可以使用
DecimalFormat

公共类DecimalFormat扩展了NumberFormat

DecimalFormat是NumberFormat的一个具体子类,用于格式化 十进制数。它有各种各样的功能设计来实现它 可以在任何语言环境中解析和格式化数字,包括支持 用于西文、阿拉伯文和印度文数字。它还支持不同的应用程序 数的种类,包括整数(123)、定点数 (123.4%)、科学记数法(1.23E4)、百分比(12%)和货币 数额(123美元)。所有这些都可以本地化

请看这里

  • 所以试着这样做

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

    您的实际
    分数是多少?您是否试图在每3位数字后添加一个“.”。请看这里,这将很有帮助