zoukankan      html  css  js  c++  java
  • Math类的常用方法

    System.out.println("返回参数的绝对值:" + Math.abs(-9)); //9
    //ceil天花板的意思,就是返回大的值,注意一些特殊值
    System.out.println("对整形变量向上取整,返回类型为double型:" + Math.ceil(-8.7)); //-8.0
    System.out.println(Math.ceil(8.7)); //9.0
    System.out.println(Math.ceil(8.1)); //9.0
    //floor地板的意思,就是返回小的值
    System.out.println("对整型变量向下取整。返回类型为double类型:" + Math.floor(-8.1)); //-9.0
    System.out.println(Math.floor(8.9)); //8.0
    //rint 四舍五入,返回double值 (注意.5的时候会取偶数 )
    System.out.println("返回与参数最接近的整数。返回类型为double: " + Math.rint(4.5)); //4.0
    System.out.println(Math.rint(11.5)); //12.0
    System.out.println(Math.rint(10.5)); //10.0
    //round 四舍五入,float时返回int值,double时返回long值
    System.out.println("返回一个最接近的int、long型值:" + Math.round(5.5)); //6
    // random 取得一个大于或者等于0.0小于不等于1.0的随机数
    System.out.println("返回一个随机数:"+Math.random());

  • 相关阅读:
    506. 相对排名 Relative Ranks
    500. 单词是否在键盘上的同一行 Keyboard Row
    openstack live migration性能分析
    libvirt/qemu特性之numa
    nova Scheduling 配置
    Specify compute hosts with SSDs
    nova conductor
    osprofiler
    watcher
    stacktach和ceilometer
  • 原文地址:https://www.cnblogs.com/gaomanito/p/8311024.html
Copyright © 2011-2022 走看看