用Math.round()或BigDecimal 保存两位小数 效率为什么会很低很低呢?
xling 2011-07-18 10:08:53 程序中想对数组中一元素p[j]进行四舍五入保留小数点后两位的操作,用:
float a = (float)(nodeDegree[j])/sumOfDegree;
BigDecimal b = new BigDecimal((double)a);
p[j] = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
和
p[j] = (float)Math.round(((float)(nodeDegree[j])/sumOfDegree)*100)/100;
发现程序跑的非常慢,请教大虾们这是什么原因呢?