细想java格式化 format()

 format("I have %.2f bugs to fix", 128.190902); 

这里  % 的位置,是129.190902的位置, .2f 代表改参数要使用的格式

数值的精确度会有所损失, 这样只会保留 2位小数

f或d 这样的type都是格式化指令

6.1f 表示 保留6位数字 小数点后面有1位  格式是float

 1 //传入多个参数
 2 
 3 int one = 20456654;
 4 double two = 100567890.248907;
 5 String s = String.format("The rank is %,d out of %,.2f",one,two);
 6 
 7 
 8 
 9 
10 //结果为
11 // The rank is 20,456,654 out of 100,567,890,25
12 //相信你也注意到了 ,   这个东西
原文地址:https://www.cnblogs.com/qiuyehaha/p/13160723.html