集册 Java实例教程 使用Math.round对浮点数和双数取整

使用Math.round对浮点数和双数取整

欢马劈雪     最近更新时间:2020-01-02 10:19:05

519
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Math.round对浮点数和双数取整


public class Main {

 

  public static void main(String[] args) {
  /*
  来 自*
   n o w j a   v  a . c o m - 时  代  Java
  */

     System.out.println(Math.round(10f));

   

     System.out.println(Math.round(1.5f));

   

     System.out.println(Math.round(120.5f));

   

     System.out.println(Math.round(-129.4f));

   

     System.out.println(Math.round(-123.5f));

   

  }

}