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

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

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

瀏覽:7日期: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
相關文章:
主站蜘蛛池模板: 亚洲国产精品一区二区三区 | 国产精品一区二区三区四区 | 黄色影| 亚洲综合在线播放 | 国产一区二区三区在线免费 | 久久亚洲这里只有精品18 | 日韩国产精品99久久久久久 | 黄色欧美网站 | 中文字幕亚洲精品第一区 | 98国产精品永久在线观看 | 亚洲一级在线观看 | 日韩一本 | 精品国产麻豆免费网站 | 伊人久久精品午夜 | 曰曰鲁夜夜免费播放视频 | 国产在线不卡免费播放 | 福利国产 | 黄色在线看网站 | 看全色黄大色黄女片爽老外 | 国产成人v视频在线观看 | 免费视频一级片 | 精品入口麻豆 | 国产成人影视 | 欧美激情艳三级 | 久久er国产精品免费观看1 | 国产精品久久成人影院 | 中文字幕久久亚洲一区 | 日本高清另类videohd | 国内色视频 | 国产精品久久免费 | 青青草久热精品视频在线观看 | 欧美性视频一区二区三区 | 亚洲精品国产精品乱码不卞 | 国产一级黄色片子 | 免费影院在线 | 国产精选自拍 | 久久久免费视频播放 | 天天久久综合 | 国产精品欧美在线不卡 | 毛片一级 | 一区二区不卡在线 |