gpt4 book ai didi

java - 如何设置文本编号格式?

转载 作者:行者123 更新时间:2023-11-30 01:49:02 25 4
gpt4 key购买 nike

我使用这个方法来将 int 的值显示到 TextView 中

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

所以会这样显示

enter image description here

但是我想把数字文本格式变成这样,有可能吗?

enter image description here

最佳答案

您可以使用 DecimalFormat

公共(public)类 DecimalFormat 扩展 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.

请看这里

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

所以试试这个方法,

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

Logic Courtesy

关于java - 如何设置文本编号格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33326446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com