//val用于处理双精度数,precision是保留小数位数。
public static Double roundDouble(double val, int precision) {
双 ret = null;
试试{
双因子 = Math.pow(10, 精度);
ret = Math.floor(val * 因子 + 0.5) / 因子;
} 捕捉(异常 e){
e.printStackTrace();
}
返回 ret;
}
// 格式化数据
//将小数转化为百分数,保留2位小数,四舍五入,例:35.21%
public static String formatRates(double val ) {
Double ret = null;
val = val*100 ;
int precision = 2 ;
try {

double factor = Math.pow(10, precision);
ret = new Double(Math.floor(val * factor + 0.5) / factor);
} catch (Exception e) {
e.printStackTrace();
}
String tmp = String.valueOf(ret);
if (tmp.substring(tmp.indexOf('.')+1).length()<2){
tmp = tmp + "0" ;
}

return tmp + "%";
}
写
public static String getRoundValue(double value,int digit) {
digit = (digit < 0 ? 0 : digit );
String s = String.valueOf(new BigDecimal(value).setScale(digit, BigDecimal.ROUND_HALF_UP)
.doubleValue());
return (digit == 0 ? (s.substring(0,s.indexOf(‘.’))) : s);
}
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 欧资源网