`
linjiacheng
  • 浏览: 70652 次
  • 性别: Icon_minigender_1
  • 来自: 中國
社区版块
存档分类
最新评论

java四舍五入

阅读更多
	private static int getRound(double dSource){
		int iRound;
		BigDecimal deSource = new BigDecimal(dSource);
		iRound= deSource.setScale(0,BigDecimal.ROUND_HALF_UP).intValue();
		return iRound;
	} 

	public static void main(String[] args) { 
		try { 						System.out.println("0.345 : " + getRound(0.345));
			System.out.println("0.545 : " + getRound(0.545));
			System.out.println("0.945 : " + getRound(0.945));
			System.out.println("0.045 : " + getRound(0.045));
		}catch (Exception e) { 
			e.printStackTrace(); 
		} 
	} 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics