java math 類
數學課靜態長回合(雙D) (Math Class static long round(double d) )
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程序演示round(double d)方法的示例 (Java program to demonstrate example of round(double d) method)
// 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.java
E:\Programs>java RoundMethod
Math.round(d1): -9223372036854775808
Math.round(d2): 9223372036854775807
Math.round(d3): 1235
Math.round(d4): 1234
翻譯自: https://www.includehelp.com/java/math-class-static-long-round-double-d-with-example.aspx
java math 類