本文共 3269 字,大约阅读时间需要 10 分钟。
java math 类
This method is available in java.lang package.
此方法在java.lang包中可用。
This method is used to return the closest long value to the given argument.
此方法用于将最接近的long值返回给定参数。
This is a static method, it is accessible with the class name too.
这是一个静态方法,也可以使用类名进行访问。
The return type of this method is long, it returns the long type number which will be converted from double floating to long by adding 1/2 of the given argument.
此方法的返回类型为long ,它返回long类型号,通过添加给定参数的1/2可以将其从double浮点数转换为long类型。
In this method, we pass only one parameter of a double type value.
在此方法中,我们仅传递一个double类型值的参数。
If the value of the given argument after the decimal point is greater than 4 then the value is incremented by 1 before the decimal point is returned else if the value of the given argument after the decimal point is less than or equal to 4 then the same value before the decimal point is returned.
如果小数点后给定参数的值大于4,则在返回小数点前将值加1;否则,如果小数点后给定参数的值小于或等于4,则相同返回小数点前的值。
This method does not throw any exception.
此方法不会引发任何异常。
Syntax:
句法:
public static long round(double d){ }
Parameter(s): d – a double value whose closest to long value to be found.
参数: d –一个双精度值,其最接近要找到的long值。
Note:
注意:
If we pass "NaN" (Not a Number), it returns 0.
如果传递“ NaN”(非数字),则返回0。
If we pass negative infinity, it returns the "Long.MIN_VALUE".
如果我们传递负无穷大,它将返回“ Long.MIN_VALUE”。
If we pass positive infinity, it returns the "Long.MAX_VALUE".
如果我们传递正无穷大,它将返回“ Long.MAX_VALUE”。
If we pass the value which is less than or equal to "Long.MIN_VALUE", it returns "Long.MIN_VALUE".
如果传递的值小于或等于“ Long.MIN_VALUE”,则返回“ Long.MIN_VALUE”。
If we pass the value which is greater than or equal to "Long.MAX_VALUE", it returns "Long.MAX_VALUE".
如果传递的值大于或等于“ Long.MAX_VALUE”,则返回“ Long.MAX_VALUE”。
Return value:
返回值:
The return type of this method is long, it returns a long value which is the closest to long value of given parameter.
此方法的返回类型为long ,它返回一个long值,该值最接近给定参数的long值。
// Java program to demonstrate the example of // round(double d) method of Math Class.public class RoundMethod { public static void main(String[] args) { // declaring the variables double d1 = -1.0 / 0.0; double d2 = 1.0 / 0.0; double d3 = 1234.56; double d4 = 1234.42; // Here , we will get (Long.MIN_VALUE) and we are // passing parameter whose value is (-Infinity) System.out.println("Math.round(d1): " + Math.round(d1)); // Here , we will get (Long.MAX_VALUE) and we are // passing parameter whose value is (Infinity) System.out.println("Math.round(d2): " + Math.round(d2)); // Here , we will get (1235) and we are // passing parameter whose value is (1234.56) System.out.println("Math.round(d3): " + Math.round(d3)); // Here , we will get (1234) and we are // passing parameter whose value is (1234.12) System.out.println("Math.round(d4): " + Math.round(d4)); }}
Output
输出量
E:\Programs>javac RoundMethod.javaE:\Programs>java RoundMethodMath.round(d1): -9223372036854775808Math.round(d2): 9223372036854775807Math.round(d3): 1235Math.round(d4): 1234
翻译自:
java math 类
转载地址:http://tyazd.baihongyu.com/