设置自定义格式中的TextView号 [英] Setting custom format for numbers in TextView

查看:177
本文介绍了设置自定义格式中的TextView号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  我如何在Java格式的数字?结果
  <一href=\"http://stackoverflow.com/questions/4885254/string-format-to-format-double-in-java\">String.format()格式化在Java 双


我希望能够把从双变量(称为双)输出,并把它放在一个TextView一些字符串文本一起(称为输出preF,其中只包含立方毫米)象下面

  displayAnswer.setText(音量++输出preF);

这工作得很好,然而,数字显示在TextView中的整整一倍(有很多很多位小数)。我想数量与逗号分割显示千种(如果有的话),带有一个小数位,如Excel的数字格式_(*#,## 0.0 _); _(*(#,## 0.0); _(* - ?? ); 的(@_),或者简单地说(我定不会有任何负数)
#,## 0.0

的功能是什么,我应该把它应用到TextView的使用前重新配置卷的双变量?


解决方案

 的String.format(%1 $ ,. 2F,myDouble);

Possible Duplicate:
How do I format a number in java?
String.format() to format double in java

I want to be able to take the output from a double variable (called double) and put it in a TextView along with some String text (called outputPref, which just contains "cubic mm") like below

displayAnswer.setText(volume + " " + outputPref);

This works fine, however, the number shows in the TextView as the full double (with many, many decimal places). I want the number to show with comma's splitting the thousands (if there are any) with one decimal place, like the Excel number format "_(* #,##0.0_);_(* (#,##0.0);_(* "-"??);(@_)", or put simply (given I won't have any negative numbers) "#,##0.0"

What is the function I should use to reconfigure the volume double variable before applying it to the TextView?

解决方案

String.format("%1$,.2f", myDouble);

这篇关于设置自定义格式中的TextView号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆