java中的Math.ceil、Math.floor和Math.round
ceil意为天花板,指向上取整;floor意为地板,指向下取整;round指四舍五入
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));//
System.out.println(Math.round(11.5));//
System.out.println(Math.round(11.6));//
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.round的更多相关文章
- Javascript Math ceil()、floor()、round()三个函数的区别
Round是四舍五入的...Ceiling是向上取整..float是向下取整. ceil():将小数部分一律向整数部分进位. 如: Math.ceil(12.2)//返回13 Math.ceil(12 ...
- 数学对象Math ceil()、floor()、round()方法
Math.ceil() 功能:对一个数进行上取整. 语法:Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”: ...
- Jquery Math ceil()、floor()、round()比较与用法
Math.ceil():向上取值 如:Math.ceil(2.1) -- 结果为 3 Math.ceil(-2.1) -- 结果为-2 结论:正入 负舍 Math.floor(): 先下取值 入 ...
- Math.ceil()、floor()、round()
ceil():向上取整,>=某个小数的最小整数,即15.3取16.返回double类型 如果参数小于0且大于-1.0,结果为 -0. floor():向下取整,<=某个小数的最大整数,即1 ...
- 一:SqlServer中的 CEILING函数和 FLOOR函数以及ROUND()
例如 1.ROUND() 格式为ROUND(y1,y2,y3) y1:要被四舍五入的数字y2:保留的小数位数 y3:为0,可以不写,y1进行四舍五入,不为0则y1不进入四舍五入,如果y1有值就直接根据 ...
- JS 中Math.ceil()、Math.floor()和Math.round()的区别
var arg1 = 12.2; var arg2 = 12.5; var arg3 = 12.7; ceil():将小数部分一律向整数部分进位 var c1 = Math.ceil(arg1); v ...
- js 中的 Math.ceil() Math.floor Math.round()
alert(Math.ceil(25.9)); alert(Math.ceil(25.5)); alert(Math.ceil(25.1)); alert(Math.round(25.9)); ale ...
- java中的Math类
一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等 在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型的情形.为了解决这个问题,Ja ...
- callable函数 stride的意义 Math.round(),Math.ceil(),Math.floor()用法
callable()函数检查一个函数是否可以调用 如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 对于函数, 方法, lambda 函式, 类 ...
- JS单体内置对象之Math常用方法(min,max,ceil,floor,round,random等)
1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...
随机推荐
- 【原创】(三)Linux paging_init解析
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...
- Java 添加Word文本框
在Word中,文本框是指一种可移动.可调节大小的文字或图形容器.我们可以向文本框中添加文字.图片.表格等对象,下面,将通过Java编程来实现添加以上对象到Word文本框. 使用工具:Free Spir ...
- ASP.NET MVC实现依赖注入
在java的spring中有自动注入功能,使得代码变得更加简洁灵活,所以想把这个功能移植到c#中,接下来逐步分析实现过程 1.使用自动注入场景分析 在asp.net mvc中,无论是什么代码逻辑分层, ...
- 新手学习FFmpeg - 通过API完成filter-complex功能
本篇尝试通过API实现Filter Graph功能. 源码请参看 https://andy-zhangtao.github.io/ffmpeg-examples/ FFmpeg提供了很多实用且强大的滤 ...
- zookeeper的未授权访问漏洞解决
zookeeper的基本情况 zookeeper是分布式协同管理工具,常用来管理系统配置信息,提供分布式协同服务.zookeeper官网下载软件包,bin目录下有客户端脚本和服务端脚本.另外还有个工具 ...
- Redis常用命令(key、string、List)
1.Key 1.keys * 查询所有数据 2.exists key名 判断key名是否存在 3.move key名 数据库号(0-15) 移动数据key名到相应的数据库 4.expire ...
- 5、链表队列(java实现)
1.图例 2.链表节点 public class Node<T> { public T data; public Node next; } 3.具体实现 public class Link ...
- eclipse下mybatis-generator-config插件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
- 第1次作业:使用Packet Tracer分析HTTP数据包
个人信息: • 姓名:李微微 • 班级:计算1811 • 学号:201821121001 一.摘要 本文将会描述使用Packet Tracer工具用到的网络结构 ...
- C#加载前生成静态网页
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...