• Math.round(11.5)等于()Math.round(-11.5)等于()


    几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的。并不断使用和复习才会成为高手,假设基础不是那么熟练。恐怕在成为高手的路上会困难重重。所以在做项目的间歇时间。偶尔回顾一下最基础的知识。是一个比較好的投资。

    好了。以下介绍的就是Math类中三个与取整有关的方法 :

    1、Math.round();//四舍五入

    2、Math.ceil();//向上取整

    3、Math.floor();//向下取整

    代码展示:

    public class TextOne {
    	public static void main(String[] args) {
    		/**
    		 * 四舍五入取整
    		 */
    		System.out.println(Math.round(11.5));
    		System.out.println(Math.round(-11.5));
    		
    		/**
    		 *向上取整 
    		 */
    		System.out.println(Math.ceil(11.5));
    		System.out.println(Math.ceil(-11.5));
    		
    		/**
    		 * 向下取整
    		 */
    		System.out.println(Math.floor(11.5));
    		System.out.println(Math.floor(-11.5));
    		
    	}
    }

    执行结果:

    12
    -11
    12.0
    -11.0
    11.0
    -12.0





     

  • 相关阅读:
    分页实现
    jquery扩展提示框
    可拖拽可扩展面板
    单表查询结果转换成泛型集合
    压缩远程图片并返回
    windows下python安装架包的问题
    从网络上下载数据
    自己实现jquery
    如何利用拼音首字母查询数据库
    正则表达式
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5209113.html
Copyright © 2020-2023  润新知