http://blog.csdn.net/yuhua3272004/article/details/3075436 使用java.math.BigDecimal工具类实现 java保留两位小数问题: 方式一(四舍五入形式保留两位小数,注意模式ROUND_HALF_UP): 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale
public final class Math extends Object public static double floor(double a) public static long round(double a) public static int round(float a) public static double ceil(double a) floor 返回不大于的最大整数;ceil 则是不小于他的最小整数;round 它表示"四舍五入"
ceil意为天花板,指向上取整:floor意为地板,指向下取整:round指四舍五入 package com.company; public class Main { public static void main(String[] args) { //向上取整 System.out.println(Math.ceil(11.3));//12.0 System.out.println(Math.ceil(-11.3));//-11.0 //向下取整 System.out.println(Math
package com.test; /* Math类: java.lang.Math类中包含基本的数字操作,如指数.对数.平方根和三角函数. java.math是一个包,提供用于执行任意精度整数(BigInteger)算法和任意精度小数(BigDecimal)算法的类. java.lang.Math类中包含E和PI两个静态常量,以及进行科学计算的类(static)方法,可以直接通过类名调用. public static final Double E = 2.7182818284590452354
Math类 Math的方法 package cn.itcast_01; /* * Math:用于数学运算的类. * 成员变量: * public static final double PI * public static final double E * 成员方法: * public static int abs(int a):绝对值 * public static double ceil(double a):向上取整 * public static double floor(double a
Math类: java.lang.Math 类中包含基本的数字操作,如指数.对数.平方根和三角函数. java.math是一个包,提供用于执行任意精度整数(BigInteger)算法和任意精度小数(BigDecimal)算法的类. java.lang.Math 类中包含E和PI两个静态常量,以及进行科学计算的类(static)方法,可以直接通过类名调用. public static final Double E = 2.7182818284590452354 public static fina