Math.round()

更新时间:2025-05-08 09:29:29 阅读: 评论:0

Math.round()

Math.round()是一个计算机函式,可以用来进行数学运算。

简介

就是四捨五入!‘public class MathTest {public static void main(String[] args) {System.out.println("小数点后第一位=5");System.out.println("正数:Math.round(11.5)=" + Math.round(11.5));System.out.println("负数:Math.round(-11.5)=" + Math.round(-11.5));System.out.println();System.out.println("小数点后第一位<5");System.out.println("正数:Math.round(11.46)=" + Math.round(11.46));System.out.println("负数:Math.round(-11.46)=" + Math.round(-11.46));System.out.println();System.out.println("小数点后第一位>5");System.out.println("正数:Math.round(11.68)=" + Math.round(11.68));System.out.println("负数:Math.round(-11.68)=" + Math.round(-11.68));}}

运行结果

1、小数点后第一位=52、正数:Math.round(11.5)=123、负数:Math.round(-11.5)=-114、5、小数点后第一位<56、正数:Math.round(11.46)=117、负数:Math.round(-11.46)=-118、9、小数点后第一位>510、正数:Math.round(11.68)=1211、负数:Math.round(-11.68)=-12根据上面例子的运行结果,我们还可以按照如下方式总结,或许更加容易记忆:1、参数的小数点后第一位<5,运算结果为参数整数部分。2、参数的小数点后第一位>5,运算结果为参数整数部分绝对值+1,符号(即正负)不变。3、参数的小数点后第一位=5,正数运算结果为整数部分+1,负数运算结果为整数部分。总结:大于五全部加,等于五正数加,小于五全不加。

本文发布于:2023-03-25 07:01:06,感谢您对本站的认可!

本文链接:http://www.ranqi119.com/to/1679771858224160.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Math
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 站长QQ:55-9-10-26|友情:优美诗词|电脑我帮您|扬州装修|369文学|站长工具|软件玩家|水木编程|编程频道