日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Java语言中小数的取整

發布時間:2023/12/19 综合教程 30 生活家
生活随笔 收集整理的這篇文章主要介紹了 Java语言中小数的取整 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、double java.lang.Math.floor(double a)

返回最大的double值(在正無窮方向上最接近的)小于或等于參數a的一個數學意義上的整數,特例:

如果參數值等于數學上的整數,則返回結果與參數值相同

如果參數是NaN(非數值)或是無窮或是+0或是-0,則返回值和參數值相同

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:

If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Math.floor(2.0)=2.0
Math.floor(2.1)=2.0
Math.floor(2.5)=2.0
Math.floor(2.9)=2.0

Math.floor(-2.0)=-2.0

Math.floor(-2.1)=-3.0

Math.floor(-2.5)=-3.0

Math.floor(-2.9)=-3.0

2、double java.lang.Math.ceil(double
a)
返回最小的double值(在負無窮方向最接近的)大于或等于參數a的一個數學意義上的整數,特例:

如果參數值已經等于一個數學意義上的整數,則返回結果與參數相同
如果參數是NaN(非數值)或者是無窮,或是+0,-0,則返回結果與參數相同
如果參數值小于0或大于-1.0

Returns the smallest (closest to negative
infinity) double value that is greater than or equal
to the argument and is equal to a mathematical integer. Special
cases:

If the argument value is already equal to
a mathematical integer, then the result is the same as the
argument.
If the argument is NaN or an infinity or
positive zero or negative zero, then the result is the same as the
argument.
If the argument value is less than zero
but greater than -1.0, then the result is negative
zero.

Math.ceil(2.0)=2.0

Math.ceil(2.1)=3.0

Math.ceil(2.5)=3.0

Math.ceil(2.9)=3.0


Math.ceil(-2.0)=-2.0

Math.ceil(-2.1)=-2.0

Math.ceil(-2.5)=-2.0

Math.ceil(-2.9)=-2.0


double java.lang.Math.rint(double
a)

Returns the double value that
is closest in value to the argument and is equal to a mathematical
integer. If two double values that are mathematical
integers are equally close, the result is the integer value that is
even. Special cases:

If the argument value is already equal to
a mathematical integer, then the result is the same as the
argument.
If the argument is NaN or an infinity or
positive zero or negative zero, then the result is the same as the
argument.

Math.rint(2.0)=2.0

Math.rint(2.5)=2.0

Math.rint(2.6)=3.0

Math.rint(2.9)=3.0


Math.rint(-2.0)=-2.0

Math.rint(-2.5)=-2.0

Math.rint(-2.6)=-3.0

Math.rint(-2.9)=-3.0


long java.lang.Math.round(double
a)

Returns the closest long to
the argument. The result is rounded to an integer by adding 1/2,
taking the floor of the result, and casting the result to type
long. In other words, the result is equal to the value
of the expression:

(long)Math.floor(a + 0.5d)

Special cases:

If the argument is NaN, the result is 0.
If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.

Math.round(2.0)=2
Math.round(2.5)=3
Math.round(2.6)=3
Math.round(2.9)=3

Math.round(-2.0)=-2

Math.round(-2.5)=-2

Math.round(-2.6)=-3

Math.round(-2.9)=-3



總結

以上是生活随笔為你收集整理的Java语言中小数的取整的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。