---
title: "对数字进行四舍五入的方法"
author: "windy_star"
date: "2010-12-28T16:35:34Z"
tags: ["Java"]
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-12-28T16:35:34Z"
id: 854021
url: "https://windy-star.iteye.com/blog/854021"
---

使用Math中的round方法

```java

import java.util.*;

public class qwe {
	public static void main(String[] args) {
		double above = 0.7, below = 0.4;
		float fabove = 0.7f, fbelow = 0.4f;

		System.out.println("Math.round(above)" + Math.round(above));
		System.out.println("Math.round(above)" + Math.round(below));
		System.out.println("Math.round(above)" + Math.round(fabove));
		System.out.println("Math.round(above)" + Math.round(fbelow));

	}

}


```



结果为:1
       0
       1
       0