av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Java Math類的三個方法ceil,floor,round用法

瀏覽:3日期:2022-08-09 11:00:48
Math類的ceil,floor,round用法ceil()方法

就表示向上取整,Math.ceil(12.3)的結果是13,Math.ceil(-12.7)的結果-12;

floor()方法

就表示向下取整,Math.floor(12.7)的結果是12,Math.floor(-12.3)的結果-13;

round()方法

表示“四舍五入”,Math.round(12.3)的結果是12,Math.round(-12.7)的結果-13;

Math的 floor,round和ceil總結

floor 返回不大于的最大整數

round 則是4舍5入的計算,入的時候是到大于它的整數

round方法,它表示“四舍五入”,算法為Math.floor(x+0.5),即將原來的數字加上0.5后再向下取整,所以,Math.round(11.5)的結果為12,Math.round(-11.5)的結果為-11。

ceil 則是不小于他的最小整數

看例子 Math.floor Math.round Math.ceil 1.4 1 1 2 1.5 1 2 2 1.6 1 2 2 -1.4 -2 -1 -1 -1.5 -2 -1 -1 -1.6 -2 -2 -1

測試程序如下:

public class MyTest { public static void main(String[] args) { double[] nums = { 1.4, 1.5, 1.6, -1.4, -1.5, -1.6 }; for (double num : nums) { test(num); } } private static void test(double num) { System.out.println('Math.floor(' + num + ')=' + Math.floor(num)); System.out.println('Math.round(' + num + ')=' + Math.round(num)); System.out.println('Math.ceil(' + num + ')=' + Math.ceil(num)); } }

運行結果

Math.floor(1.4)=1.0Math.round(1.4)=1Math.ceil(1.4)=2.0Math.floor(1.5)=1.0Math.round(1.5)=2Math.ceil(1.5)=2.0Math.floor(1.6)=1.0Math.round(1.6)=2Math.ceil(1.6)=2.0Math.floor(-1.4)=-2.0Math.round(-1.4)=-1Math.ceil(-1.4)=-1.0Math.floor(-1.5)=-2.0Math.round(-1.5)=-1Math.ceil(-1.5)=-1.0Math.floor(-1.6)=-2.0Math.round(-1.6)=-2Math.ceil(-1.6)=-1.0

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 黄一区二区三区 | 久久精品国产a三级三级三级 | 国产三区精品 | 伊人网在线看 | 亚洲欧美日韩国产综合 | 日本不卡免费新一二三区 | 一级毛毛片| 精品久久香蕉国产线看观看亚洲 | 精品国产一级片 | 欧美午夜一区 | 中文字幕在线观看一区 | 午夜影院在线播放 | 日韩成人免费视频 | 三级视频国产 | 中文字幕亚洲一区二区三区 | 国产98色在线 | 日韩 | 国产视频黄色 | 91黄在线观看 | 欧美精品99| 国产在线视频一区 | 2022精品国偷自产免费观看 | 综合久久久久 | 久久久男人的天堂 | 国产精品久久久久久影视 | 亚洲精品免费观看 | 欧美性影院 | 欧美三级在线 | 九九在线视频 | 99久久影院 | 手机在线不卡av | 国产成人久久精品一区二区三区 | 日韩欧美三级在线 | 亚洲国产中文字幕 | 情侣酒店偷拍一区二区在线播放 | 成人一区二区三区在线观看 | 日韩成人在线一区 | 欧美888| 一a级片 | 人人爽人人草 | 亚洲福利| 美女视频一区二区 |