zoukankan      html  css  js  c++  java
  • Java 中的 Math. round(-1. 5) 等于多少?

    Java基础

    Java 中的 Math. round(-1. 5) 等于多少?

    Math.round(-1.5)的返回值是-1。四舍五入的原理是在参数上加0.5然后做向下取整。

    它有三个特例:

    1.如果参数为 NaN(无穷与非数值) ,那么结果为 0。

    2.如果参数为负无穷大或任何小于等于 Long.MIN_VALUE 的值,那么结果等于Long.MIN_VALUE 的值。

    3.如果参数为正无穷大或任何大于等于 Long.MAX_VALUE 的值,那么结果等于Long.MAX_VALUE 的值。

    public class test {
    	public static void main(String[] args){
    		System.out.println(Math.round(1.3));   //1
    		System.out.println(Math.round(1.4));   //1
    		System.out.println(Math.round(1.5));   //2
    		System.out.println(Math.round(1.6));   //2
    		System.out.println(Math.round(1.7));   //2
    		System.out.println(Math.round(-1.3));  //-1
    		System.out.println(Math.round(-1.4));  //-1
    		System.out.println(Math.round(-1.5));  //-1
    		System.out.println(Math.round(-1.6));  //-2
    		System.out.println(Math.round(-1.7));  //-2
    	}
    }
    
  • 相关阅读:
    VIM配置
    VSCode配置Import@路径
    Sar
    VIM-Fold折叠
    sysctl
    java8 到 java14新增的特性
    Electron整合VUE
    使用Markfile开发GO程序
    cron 表达式
    java spi
  • 原文地址:https://www.cnblogs.com/coderD/p/13828628.html
Copyright © 2011-2022 走看看