色综合图-色综合图片-色综合图片二区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
相關文章:
主站蜘蛛池模板: 精品综合久久久久久99 | 日本免费久久 | 窝窝女人体国产午夜视频 | 国产欧美一区视频在线观看 | 免费人成在观看 | 欧美成人性色xxxxx视频大 | 欧美aaaaa一级毛片在线 | 亚洲六月丁香六月婷婷蜜芽 | 女人成午夜大片7777在线 | 手机看片免费基地 | 欧美做爰野外在线视频观看 | 一级毛片免费不卡在线视频 | 大陆老头xxxxxhd| 青青草国产免费一区二区 | 欧美激情久久久久久久大片 | 免费老外的毛片清高 | 中文字幕亚洲精品第一区 | 亚洲免费久久 | 极品国产在线 | 97在线免费 | 最近最新中文字幕免费的一页 | 日本高清视频一区二区 | 91精品国产91久久久久青草 | jizz国产精品免费麻豆 | 国产成人毛片毛片久久网 | 亚洲一区2区三区4区5区 | 国产欧美在线观看视频 | 色黄啪啪18周岁以下禁止观看 | 国产精品黄页网站在线播放免费 | 97青草香蕉依人在线播放 | 欧美日韩成人午夜免费 | 91免费高清视频 | 日韩专区亚洲国产精品 | 亚洲特黄视频 | 杨幂丝袜国产福利视频 | swag国产精品一区二区 | 成人午夜大片免费看爽爽爽 | 久久精品国产第一区二区 | 欧美xxxxx毛片 | 国产精品一在线观看 | 动漫一级毛片 |