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() 这样的函数只是函数, ...
随机推荐
- 图解微信小程序---scroll_view实现首页排行榜布局
图解微信小程序---scroll_view实现首页排行榜布局 什么是scroll-view? 滚动视图可滚动视图区域.使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 h ...
- tkmybatis VS mybatisplus
本文是简单对比了以下官网上的内容 文章目录 TkMybatis Vs MybatisPlus 1.基础CRUD BaseMapper 2.代码生成器 3. 全局主键 Sequence主键 4. 热加载 ...
- excel中使用统计列中的值在其他列出现的次数
excel中使用统计一列的中值在其他列出现的次数 =COUNTIFS($J$:$J$,K2) 解释下 $J$2 J列中的第二行到 $J$373 J列的373行 范围内 查找 k列的第二行的值 出现的 ...
- ActiveMq C# 消息特性:延迟和定时消息投递
ActiveMQ from version 5.4 has an optional persistent scheduler built into the ActiveMQ message broke ...
- SQLServer日常bug记录
问题1:如下图所示 原因分析:同时操作数据库中的两条数据引起的 解决方法:新建查询语句 delete 数据库名字.表名 where 引起错误的字段=引起错误的字段值
- APS中生产计划排程模块的基本原理
高级计划系统(APS)作为ERP和MES的补充,用于协调物流.开发瓶颈资源和保证交货日期. APS包括需求和供应计划.运输和生产计划排程等各种供应链计划模块,本文主要介绍APS中生产计划排程模块的基本 ...
- 一些你所不知道的VS Code插件
摘要: 你所不知道的系列. 原文:提高 JavaScript 开发效率的高级 VSCode 扩展之二! 作者:前端小智 Fundebug经授权转载,版权归原作者所有. 作为一名业余爱好者.专业人员,甚 ...
- springboot搭建dubbo+zookeeper简单案例
背景:只是自己使用单机版zookeeper搭建dubbo的一个学习案例,记录成功的过程 1.搭建zookeeper坏境 使用docker来构建环境 1.1 拉取镜像:docker pull zooke ...
- Python从零开始——基本数据类型
- Linux的httpd服务介绍和部署
软件介绍 客户端代理软件 IE,firefox,chroome,opera 服务器端软件 httpd,Nginx,Tengine,ISS,Lighthttp 应 ...