数字的格式化------number<----->String

转换格式类DecimalFormat:

new  DecimalFormat("0.##%")-----百分比(显示2位小数)
new  DecimalFormat("000,000,000.##%")-----从左到右每3位显示1个逗号(显示2位小数)


                  指定格式
字符串-----------------〉数字
将“5.6%”-------〉转换为数字
String s ="5.6%";
DecimalFormat  fmt = new  DecimalFormat("0.##%"); //#:表示必须有,0:表示可有可无
double  d =fmt.parse(s).doubleValue(); // 0.05599999999999999994


         按指定格式
数字----------------〉字符串
double  x =0.07555555;
DecimalFormat  fmt = new  DecimalFormat("0.##%");
String  s = fmt.format(x);  // 7.56%

猜你喜欢

转载自2277259257.iteye.com/blog/2088701