strictmath_Java StrictMath rint()方法与示例
strictmath
StrictMath類rint()方法 (StrictMath Class rint() method)
rint() Method is available in java.lang package.
rint()方法在java.lang包中可用。
rint() Method is used to return the double type value and if the value of the given argument after 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 decimal point is less than or equal to 4 then the same value before the decimal point is returned.
rint()方法用于返回雙精度類型值,如果小數(shù)點(diǎn)后給定參數(shù)的值大于4,則在返回小數(shù)點(diǎn)前將值加1,否則,如果小數(shù)點(diǎn)后給定參數(shù)的值如果小數(shù)點(diǎn)小于或等于4,則返回小數(shù)點(diǎn)前的相同值。
rint() Method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
rint()方法是一個(gè)靜態(tài)方法,因此可以使用類名進(jìn)行訪問(wèn),如果嘗試使用類對(duì)象訪問(wèn)該方法,則不會(huì)出現(xiàn)任何錯(cuò)誤。
rint() Method does not throw any exception.
rint()方法不會(huì)引發(fā)任何異常。
Syntax:
句法:
public static double rint(double d);Parameter(s):
參數(shù):
double d – represents a double type value.
double d –表示雙精度型值。
Return value:
返回值:
The return type of the method is double, it returns the double floating point number which will be equivalent to mathematical integer.
該方法的返回類型為double ,它返回等于數(shù)學(xué)整數(shù)的雙精度浮點(diǎn)數(shù)。
Note:
注意:
If we pass NaN, the method returns the NaN.
如果傳遞NaN,則該方法返回NaN。
If we an infinity, the method returns the same (i.e. infinity).
如果我們無(wú)窮大,則該方法將返回相同的值(即無(wú)窮大)。
If we pass an argument whose value after the decimal point is greater than 4, the method returns the value incremented by 1 before the decimal point.
如果我們傳遞的參數(shù)的小數(shù)點(diǎn)后的值大于4,則該方法返回的值在小數(shù)點(diǎn)前增加1。
If we pass zero, the method returns the same value with the same sign.
如果傳遞零,則該方法返回具有相同符號(hào)的相同值。
Example:
例:
// Java program to demonstrate the example of // rint(double d) method of StrictMath Class.public class Rint {public static void main(String[] args) {// variable declarationsdouble d1 = -0.0;double d2 = 0.0;double d3 = -1.0 / 0.0;double d4 = 1.0 / 0.0;double d5 = 1234.56;double d6 = 1234.12;// Here , we will get (-0.0) because we are // passing parameter whose value is (-0.0)System.out.println("StrictMath.rint(d1): " + StrictMath.rint(d1));// Here , we will get (0.0) and we are // passing parameter whose value is (0.0)System.out.println("StrictMath.rint(d2): " + StrictMath.rint(d2));// Here , we will get (-Infinity) and we are // passing parameter whose value is (-Infinity)System.out.println("StrictMath.rint(d3): " + StrictMath.rint(d3));// Here , we will get (Infinity) and we are// passing parameter whose value is (Infinity)System.out.println("StrictMath.rint(d4): " + StrictMath.rint(d4));// Here , we will get (1235.0) and we are // passing parameter whose value is (1234.56)System.out.println("StrictMath.rint(d5): " + StrictMath.rint(d5));// Here , we will get (1234.0) and we are // passing parameter whose value is (1234.12)System.out.println("StrictMath.rint(d6): " + StrictMath.rint(d6));} }Output
輸出量
StrictMath.rint(d1): -0.0 StrictMath.rint(d2): 0.0 StrictMath.rint(d3): -Infinity StrictMath.rint(d4): Infinity StrictMath.rint(d5): 1235.0 StrictMath.rint(d6): 1234.0翻譯自: https://www.includehelp.com/java/strictmath-rint-method-with-example.aspx
strictmath
總結(jié)
以上是生活随笔為你收集整理的strictmath_Java StrictMath rint()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql镜像远程连接_docker 创
- 下一篇: Java CharArrayWriter