Java百分比、BigDecimal小数互转

来源:互联网 发布:暗黑战神 源码 编辑:程序博客网 时间:2024/05/21 14:53

1、百分比转为BigDecimal小数

String percent="66.60%";percent=percent.replace("%","");Float f = Float.valueOf(percent) / 100;BigDecimal decimal = new BigDecimal(f);System.out.println(decimal);//-0.66600000858306884765625

2、BigDecimal小数转为百分比

DecimalFormat df = new DecimalFormat("0.00%");  BigDecimal d=new BigDecimal(0.666);String percent=df.format(d);
原创粉丝点击