在C中,printf()的语句允许在参数列表中提供的precision长度。
In C, the printf() statement allows the precision lengths to be supplied in the parameter list.
printf("%*.*f", 7, 3, floatValue);
其中星号被替换为第一和第二值分别
where the asterisks are replaced with first and second values, respectively.
我要寻找一个在Android的/ Java中的等价;的String.Format()抛出一个异常。
I am looking for an equivalent in Android/Java; String.format() throws an exception.
编辑:谢谢,@Tenner;它确实工作。
Thanks, @Tenner; it indeed works.
我用
int places = 7;
int decimals = 3;
String.format("%" + places + "." + decimals + "f", floatValue);
一个有点丑陋的(和字符串连接使得它表现不好),但它的工作原理。
A little ugly (and string concatenation makes it not perform well), but it works.