zoukankan      html  css  js  c++  java
  • java之Math类

    1.Math类:包含基本数学运算的方法的工具类(工具类,代表能够完成一系列功能的类,在使用它们时,不用创建对),通过Math类直接调用。

     1     //取绝对值
     2     System.out.println(Math.abs(-6.6));
     3     //向上取整
     4     System.out.println(Math.ceil(12.1));
     5     //向下取整
     6     System.out.println(Math.floor(12.1));
     7     //取两数最大值
     8     System.out.println(Math.max(1, 1));
     9     //取两数最小值
    10     System.out.println(Math.min(1, 3));
    11     //次幂
    12     System.out.println(Math.pow(2, 2));
    13     //随机小数
    14     System.out.println(Math.random());
         //四舍五入
         System.out.println(Math.round(1.6));

    注:用于展示保留位数DecimalFormat,

    创建对象,,调用format(),参数传入要处理的数值

    1     DecimalFormat df = new DecimalFormat("0.00");
    2     System.out.println(df.format(Math.random()));
  • 相关阅读:
    转载-MongoDB 分片集群技术
    EXT4参数优化及测试---转载
    9.16周记
    PHP优化思路
    2018.09.10-拾遗
    周记8
    落地成盒-发快递
    周记7
    GTX log 6
    Gitlab Jenkins WebHook 持续集成配置踩坑记
  • 原文地址:https://www.cnblogs.com/mlf19920916/p/12104632.html
Copyright © 2011-2022 走看看