色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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
相關文章:
主站蜘蛛池模板: 国产成人精品一区二区三在线观看 | 久久久美女视频 | 成人毛片免费看 | 91精品久久国产青草 | 成人在线观看网址 | 一级做a爱过程免费视频时看 | 国产自偷自拍 | 中文字幕在线观看一区二区 | 中文字幕人成乱码在线观看 | 国产三级做爰在线观看视频 | 青青草国产免费国产是公开 | 国产午夜精品不卡观看 | 国内精品久久久久久久亚洲 | 成人中文字幕一区二区三区 | 久久精品国产免费一区 | 欧美成年人视频 | 99久久国产综合精品1尤物 | 日本加勒比一区 | 国产亚洲福利 | 免费观看的毛片手机视频 | 大学生一级一片第一次免费 | 亚洲国产日韩a在线亚洲 | 日本一区二区高清免费不卡 | 中国老妇色xxxxx | 美国三级| 成年人黄页 | 成人在免费视频手机观看网站 | 亚洲视频网站在线观看 | 国产精品揄拍一区二区 | 国产高清在线精品 | 欧美精品人爱a欧美精品 | 99爱视频免费高清在线观看 | a一级免费视频 | 色综合a怡红院怡红院首页 色综合精品久久久久久久 色综合九九 | 国产成人精品三级91在线影院 | 免费国产成人手机在线观看 | 99久久国语露脸精品对白 | 欧美jizzhd精品欧美 | 久草精品免费 | 亚洲精彩视频在线观看 | 免费看岛国视频在线观看 |