其他分享
首页 > 其他分享> > Math:数学运算类

Math:数学运算类

作者:互联网

Math:数学运算类

提供的成员方法:
public static int abs(int a):绝对值
public static double ceil(double a):向上取整
public static double floor(double a):向下取整
public static int max(int a,int b):取两个数最大值
public static int min(int a,int b):去量个数最小值
public static double pow(double a,double b):a的b次幂
public static double random():0.0-1.0之间的随机数取不到1.0
public static long round(double a):四舍五入
public static double sqrt(double a):对一个正整数开平方根

package com.qf.day01;

import java.math.BigDecimal;

public class BigDecimalTest {

public static void main(String[] args) {
	BigDecimal bg1 = new BigDecimal("4.6");
	BigDecimal bg2 = new BigDecimal("2.4");
	BigDecimal result = bg1.add(bg2);
	System.out.println(result);
	BigDecimal result2 = bg1.subtract(bg2);
	System.out.println(result2);
	BigDecimal result3 = bg1.multiply(bg2);
	System.out.println(result3);
	BigDecimal result4 = bg1.divide(bg2,2,BigDecimal.ROUND_HALF_UP);
	System.out.println(result4);
}

}

标签:运算,int,double,bg1,static,数学,public,Math,BigDecimal
来源: https://blog.csdn.net/zhuanjiaoyujain/article/details/113050963