java中的Math.ceil、Math.floor和Math.
作者:
氨基钠 | 来源:发表于
2020-01-17 13:43 被阅读0次package com.company;
public class Main {
public static void main(String[] args) {
//向上取整
System.out.println(Math.ceil(11.3));//12.0
System.out.println(Math.ceil(-11.3));//-11.0
//向下取整
System.out.println(Math.floor(11.3));//11.0
System.out.println(Math.floor(-11.3));//-12.0
//四舍五入 算法为Math.floor(x+0.5) 即原来的数字加上0.5再向下取整
System.out.println(Math.round(11.4));//11
System.out.println(Math.round(11.5));//12
System.out.println(Math.round(11.6));//12
System.out.println(Math.round(-11.4));//-11
System.out.println(Math.round(-11.5));//-11
System.out.println(Math.round(-11.6));//-12
}
}
本文标题:java中的Math.ceil、Math.floor和Math.
本文链接:https://www.haomeiwen.com/subject/vumczctx.html
网友评论