本文介绍了设置自定义格式中的TextView号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!