Math的round方法
代码如下,后面的注释是输出的结果
public static void main(String[] args) {
System.out.println(Math.round(0.399));//
System.out.println(Math.round(0.4));//
System.out.println(Math.round(0.41));//
System.out.println(Math.round(0.499));//
System.out.println(Math.round(0.5));//
System.out.println(Math.round(0.51));//
System.out.println(Math.round(0.6));//
System.out.println("======================");
System.out.println(Math.round(-0.6));//-1
System.out.println(Math.round(-0.51));//-1
System.out.println(Math.round(-0.5));//
System.out.println(Math.round(-0.499));//
System.out.println(Math.round(-0.41));//
System.out.println(Math.round(-0.4));//
System.out.println(Math.round(-0.399));//
}
总结,round的进位是向数轴的右方向进位的,而不是按照数的绝对值进行四舍五入的
关于Math对三角函数表示的一些知识点查看https://blog.csdn.net/River_Continent/article/details/80637952
Math的round方法的更多相关文章
- JS Math.round()方法原理
请先测试代码: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- C#中,使用显式类型转换(int)和Math.Round方法,将浮点数转换为整数的区别
主要区别就是,显式类型转换(int)是将浮点数的整数部分截取出来,然后转换为整数,所以相当于是向下取整.而Math.Round方法是对浮点数进行四舍五入后,转换为整数. 新建一个.NET Core控制 ...
- 【转载】 C#使用Math.Round方法对计算结果进行四舍五入操作
在C#的数值运算中,有时候需要对计算结果进行四舍五入操作,此时就可使用内置方法Math.Round方法来实现四舍五入操作,Math.Round方法有多个重载函数,支持设置有效位数进行四舍五入,如果没有 ...
- JS对象 四舍五入round() round() 方法可把一个数字四舍五入为最接近的整数。 语法: Math.round(x)
四舍五入round() round() 方法可把一个数字四舍五入为最接近的整数. 语法: Math.round(x) 参数说明: 注意: 1. 返回与 x 最接近的整数. 2. 对于 0.5,该方法将 ...
- Math.round方法、String实例化
math.round(11.5)==12 传入的值是11.5,通过math.round方法进行四舍五入变成12(把一个数字舍入为最接近的整数) string s = new string("xyz") ...
- JavaScript中Math对象的方法介绍
1.比较最值方法 比较最值有两种方法,max() 和 min() 方法. 1.1 max() 方法,比较一组数值中的最大值,返回最大值. var maxnum = Math.max(12,6,43,5 ...
- Math 对象的方法
Math 对象的方法 方法 描述 abs(x) 返回数的绝对值 acos(x) 返回数的反余弦值 asin(x) 返回数的反正弦值 atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返 ...
- Java重写round()方法
题目:完毕这种方法的代码实现 public static String round (String arg1, int arg2) 參数 arg1:表示等待被处理的数据:如:"100.286 ...
- javascript常用的Math对象的方法
简介 Math对象是在程序编程中用于执行一些数学任务的.Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数, ...
随机推荐
- Redis(九)高可用专栏之Sentinel模式
本文讲述Redis高可用方案中的哨兵模式--Sentinel,RedisClient中的Jedis如何使用以及使用原理. Redis主从复制 Redis Sentinel模式 Jedis中的Senti ...
- Python 3 的 int 类型详解(为什么 int 不存在溢出问题?)
在以前的Python2中,整型分为int和long,也就是整型和长整型, 长整型不存在溢出问题, 即可以存放任意大小的数值,理论支持无限大数字. 因此在Python3 中,统一使用长整型,用int表示 ...
- Linux系统SSH免密登录
第一章 生成密钥 1.1 生成用户默认文件名的密钥 [root@localhost ~] ssh-keygen -t rsa # root用户下生成root用户的默认密钥 1.2 生成用户指定文件名的 ...
- mask-rcnn解读(二):clip_boxes_graph()
此函数是利用deltas对box修正,我并没有详细说明,若有问题,欢迎留言交流: def clip_boxes_graph(boxes, window): """ box ...
- 开发工具--浅谈Git
工具|浅谈Git Git这个工具,是我一直想写文章,终于我实现了我的想法.在我开始写之前,发表一下自己的看法,git只是一个工具,既然已经认定是一个工具,那么一定具备工具这类的共同特征,请用面向对象的 ...
- eclipse对Java项目进行单元测试
一.右键项目名->buildpath->configure buildpath->add library->junit->选择版本(以4为例)->apply-> ...
- awit的用法,等待执行结果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 第一篇 Scrum 冲刺博客
一.各个成员在 Alpha 阶段认领的任务 姓名 Alpha 阶段认领的任务 林剑峰 用户信息页面:完成用户信息的上传 石竞贤 发布信息页面:完成用户图片上传云存储的功能,并且把发布信息上传到云数据库 ...
- (原)ubuntu中C++调用libotrch
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/11479240.html 参考网址: https://pytorch.org/tutorials/ad ...
- Java只有值传递(Java值传递还是引用传递?)
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10830521.html 一:区分Java数据类型.变量类型 Java数据类型分两种:基本数据类型.引用类型. ...