读书人

对数目字进行四舍五入的方法

发布时间: 2012-12-24 10:43:14 作者: rapoo

对数字进行四舍五入的方法
使用Math中的round方法

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

读书人网 >编程

热点推荐