BigDecimal类;数字格式;Random类;Math类

BigDecimal类

属于大数据类,精度极高,不属于基本数据类型,属于java对象(引用数据类型),专门用在财务软件中,财务软件中double是不够的。

public static void f1(){
    //这个100不是普通的100,是精度极高的100
    BigDecimal v1 = new BigDecimal(100);
    //精度极高的200
    BigDecimal v1 = new BigDecimal(100);
    //求和
    //v1+v2不行,都是引用,不能直接使用+求和
    BigDecimal v3 = v1.add(v2);//调用方法求和
    System.out.println(v3);//300
    BigDecimal v4 = v2.divide(v1);
    System.out.println(v4);//2
 }

数字格式

#代表任意数字

,代表千分位

.代表小数点

0代表不够时补0

DecimalFormat df = new DecimalFormat("###,###.##");
String s = df.format(1234.561232);
System.out.println(s);//"1,234.56"
DecimalFormat df2 = new DecimalFormat("###,###.0000");
String s2 = df2.format(1234.56);
System.out.println(s);//"1,234.5600"

Random类

public static void main(String[] args) {
		// 10-99
		//方法1
		Random r=new Random();
		for(int i=1;i<=10;i++)
			System.out.print(	(r.nextInt(90)+10)+"  " );//12  48  15  72  41  32  22  92  33  95  
		System.out.println();
		//方法2
		for(int i=1;i<=10;i++)
			System.out.print(  ((int)( Math.random()*90)+10)+"  ");//20  79  17  13  73  86  35  60  75  73
	}

Math类

public static void main(String[] args) {
	 //Math 类的构造方法是私有的不能生成对象,里面的方法都是静态的,通过类名访问,不需要生成对象
		//Math.random() 随机(0,1)小数
		System.out.println(Math.random()*10);
		
		System.out.println(Math.floor(3.5));//3.0 地板 向下
		System.out.println(Math.ceil(3.5));;//4.0 天花板 向上
		System.out.println(Math.round(3.5));//4四舍五入
		
		System.out.println(Math.floor(3.3));//3.0 地板 向下
		System.out.println(Math.ceil(3.3));;//4.0 天花板 向上
		System.out.println(Math.round(3.3));//3四舍五入
		
		System.out.println(Math.pow(3, 4));//81
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李拜天不上班.

感谢支持,承蒙厚爱!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值