东莞石龙网站建设定制,黄冈网站建设营销,淘宝客wordpress模板,湖北智能建站系统价格Java中四舍五入实现方法Java有四舍五入函数–Math.round#xff0c;通过一个例子看看他的用法#xff1a;[java] view plaincopypackage math;public class MathRoundTest {/*** Math类中提供了三个与取整有关的方法#xff1a;ceil,floor,round,* 这些方法的作用于它们的英…Java中四舍五入实现方法Java有四舍五入函数–Math.round通过一个例子看看他的用法[java] view plaincopypackage math;public class MathRoundTest {/*** Math类中提供了三个与取整有关的方法ceil,floor,round,* 这些方法的作用于它们的英文名称的含义相对应例如ceil的英文意义是天花板该方法就表示向上取整* Math.ceil(11.3)的结果为12Math.ceil(-11.6)的结果为-11floor的英文是地板* 该方法就表示向下取整Math.floor(11.6)的结果是11Math.floor(-11.4)的结果-12* 最难掌握的是round方法他表示“四舍五入”算法为Math.floor(x0.5),即将原来的数字加上0.5后再向下取整* 所以Math.round(11.5)的结果是12Math.round(-11.5)的结果为-11.Math.round( )符合这样的规律* 小数点后大于5全部加等于5正数加小于5全不加。*/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负数运算结果为整数部分。*/}}