午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:26日期: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
相關文章:
主站蜘蛛池模板: 久草最新视频 | 日本三级精品 | 午夜视频h | 国产探花一区二区 | 蜜色影院 | 丁香伊人 | 欧美天堂在线观看 | 337p粉嫩大胆色噜噜噜 | 日韩一级中文字幕 | 免费一区视频 | jlzzjlzz亚洲日本少妇 | 丰满老女人高潮呻吟 | 波多野结衣亚洲 | 天天做天天爽 | 激情综合激情五月 | 97超碰福利 | 黄色大片一级片 | 日韩欧美中文字幕在线播放 | 欧美成人天堂 | 亚洲影院在线播放 | 久久老女人 | 午夜视频一区二区三区 | 午夜影视福利 | 黄在线观看 | 精品国产乱 | 一区二区三区四区五区在线 | 欧美高清视频一区 | 国产精品久久久久久久久久久久久久久 | 波多野结衣在线观看一区 | 久久人人视频 | 午夜在线观看视频网站 | 2020亚洲天堂 | 国产午夜免费视频 | 亚洲一区二区在线视频 | 国内视频精品 | 日韩色影院| 浪潮av | 国产在线色 | 亚洲人在线观看 | 久久不卡免费视频 | 日韩久久久 |