问题描述
我想有一个字符串参数的strings.xml
此参数应该是一个双重价值。所以我用%1 $ F
。在这里 - http://developer.android.com/reference/java/util/Formatter html的的例子还有很多,但如果我想有什么有几个双/浮法
参数,我想只有第二个后,有2个数字。
?我试图用像%2 $ .2f
组合或 2.2%$ F
。也没有一次成功。 %。1F
不能正常工作。因此,没有任何人知道我怎么可以定制一个浮点/双精度
值在的strings.xml
?谢谢你。
I want to have a parameter in one string in strings.xml
and this parameter should be a double value. So I use %1$f
. Here - http://developer.android.com/reference/java/util/Formatter.html there are many examples, but what if I want to have have a few double/float
parameters and I want only the second one to have 2 digits after .
? I tried to use combinations like %2$.2f
or %2.2$f
. Nor of them worked. %.1f
does not work as well.So, does anybody know how can I "customize" a float/double
value inside a strings.xml
? Thanks.
推荐答案
如果是我的话我会存储在资源为简单的值的值,然后用格式化的方法来控制他们是如何显示的,大致是这样的
If it were me I'd store the values in the resources as simple values, and then use formatter methods to control how they're displayed, roughly like this
public String formatFigureTwoPlaces(float value) {
DecimalFormat myFormatter = new DecimalFormat("##0.00");
return myFormatter.format(value);
}
public String formatFigureOnePlace(float value) {
DecimalFormat myFormatter = new DecimalFormat("##0.0");
return myFormatter.format(value);
}
这篇关于双参数有2点在strings.xml中后面的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!