java中实现四舍五入
public int getRound(double dSource){
int iRound
//BigDecimal的构造函数参数类型是double
BigDecimal deSource = new BigDecimal(dSource);
//deSource.setScale(0,BigDecimal.ROUND_HALF_UP) 返回值类型 BigDecimal
//intvalue() 方法将BigDecimal转化为int
iRound= deSource.setScale(0,BigDecimal.ROUND_HALF_UP).intvalue();
return iRound;
}
public int getRound(double dSource){
int iRound
//BigDecimal的构造函数参数类型是double
BigDecimal deSource = new BigDecimal(dSource);
//deSource.setScale(0,BigDecimal.ROUND_HALF_UP) 返回值类型 BigDecimal
//intvalue() 方法将BigDecimal转化为int
iRound= deSource.setScale(0,BigDecimal.ROUND_HALF_UP).intvalue();
return iRound;
}
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}