亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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毛片视频| 国产成人精品免费久久久久 | 在线观看欧美亚洲 | 美女黄色网 | 亚洲精品午夜久久久伊人 | 2021国产麻豆剧传媒精品网站 | 久久综合综合久久 | 国产欧美国产精品第一区 | 久久久免费精品视频 | 美女被靠视频免费网站不需要会员 | 国产日韩高清一区二区三区 | 日韩黄色一级片 | 午夜精品久久久久久91 | 欧美3p在线观看一区二区三区 | 高清中国一级毛片免费 | 六月婷婷在线视频 | 欧美精品99毛片免费高清观看 | 国产精品视频在线观看 | 在线精品小视频 | 成人卡通精品卡通动漫第一页 | 国产成人av性色在线影院 | 中文字幕一区精品欧美 | 日本美女视频韩国视频网站免费 | 亚洲高清视频一区 | xxxxx亚洲| 国内精品小视频在线 | 欧洲三级| 国产女主播一区二区在线观看 | 在线观看亚洲国产 | 久久99热不卡精品免费观看 | 欧美一级毛片国产一级毛片 | 国内自拍区 | 青青草国产三级精品三级 | 污视频在线网站 | 欧美色图一区 | 免费爱爱的视频太爽了 | 色y情视频免费看 | 精品九九久久国内精品 | 精品91自产拍在线 | 看一级毛片免费观看视频 | 中国国产成人精品久久 |