java基础之Math函数

1、Math.round  四舍五入  eg:     Math.round(1.5) = 2   Math.round(1.3) = 1     Math.round(-1.5) = -1    Math.round(-1.3) = -1  Math.round(-1.8) = -2

2、Math.ceil  向上取整 eg:Math.ceil(1.5) = 2.0  Math.ceil(1.3) = 2.0    Math.ceil(-1.5) = -1.0  Math.ceil(-1.3) = -1.0  Math.ceil(-1.8) = -1.0

3、Math.floor  向下取整 eg:Math.floor(1.5) = 1.0   Math.floor(1.3) = 1.0    Math.floor(-1.5) = -2.0  Math.floor(-1.3) = -2.0  Math.floor(-1.8) = -2.0

4、Math.abs   取绝对值   eg:Math.abs(1.5) = 1.5    Math.abs(1.3) = 1.3 Math.abs(-1.5) = 1.5  Math.abs(-1.3) = 1.3  Math.abs(-1.8) = 1.8

5、Math.random():产生一个[0,1)之间的随机数。Math.random()*(n+1-m)+m   产生从m-n之间的随机数。该操作在多线程高并发的情况下,性能低下,推荐使用ThreadLocalRandom代替

6、Math.max(a,b),返回a和b的最大值 Math.max(10,3) = 10;Math.min(a,b),返回a和b的最小值 Math.min(10,3) = 3

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、介绍 Java 的 Math 包含了用于执行基本数学运算的属性和方法,如初等指数、对数、平方根和三角函数。 M...
    走着别浪阅读 2,828评论 0 2
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,143评论 0 13
  • TF API数学计算tf...... :math(1)刚开始先给一个运行实例。tf是基于图(Graph)的计算系统...
    MachineLP阅读 8,998评论 0 1
  • Math数学对象 本章单词 math 数学PI 圆周率max ...
    蛋蛋大少爷阅读 2,839评论 0 1
  • Math对象常见API(应用程序接口) -Math是 JavaScript 的原生对象(内建对象),提供各种数...
    seori阅读 1,306评论 0 0