---
title: "java四舍五入"
author: "linjiacheng"
date: "2008-07-24T16:51:38Z"
tags: ["Java", "UP"]
slug: "java"
draft: false
lastmod: "2008-07-24T16:51:38Z"
id: 219132
url: "https://linjiacheng.iteye.com/blog/219132"
---

```
	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(); 
		} 
	} 
```