数轴:-5 -4 -3 -2 -1 0 1 2 3 4 5
就是括号内的数+0.5之后,向下取值
System.out.println("1.9:__"+Math.round(1.4));// 输出1.9:__1
System.out.println("1.8:__"+Math.round(1.3));// 输出1.8:__1
System.out.println("1.7:__"+Math.round(1.2));// 输出1.7:__1
System.out.println("1.6:__"+Math.round(1.1));// 输出1.6:__1
System.out.println("1.5:__"+Math.round(1.0));// 输出1.5:__1
System.out.println("1.4:__"+Math.round(0.9));// 输出1.4:__1
System.out.println("1.3:__"+Math.round(0.8));// 输出1.3:__1
System.out.println("1.2:__"+Math.round(0.7));// 输出1.2:__1
System.out.println("1.1:__"+Math.round(0.6));// 输出1.1:__1
System.out.println("1.0:__"+Math.round(0.5));// 输出1.0:__1
System.out.println("0.9:__"+Math.round(0.4));// 输出0.9:__0
System.out.println("0.8:__"+Math.round(0.3));// 输出0.8:__0
System.out.println("0.7:__"+Math.round(0.2));// 输出0.7:__0
System.out.println("0.6:__"+Math.round(0.1));// 输出0.6:__0
System.out.println("0.5:__"+Math.round(0.0));// 输出0.5:__0
System.out.println("0.4:__"+Math.round(-0.1));// 输出0.4:__0
System.out.println("0.3:__"+Math.round(-0.2));// 输出0.3:__0
System.out.println("0.2:__"+Math.round(-0.3));// 输出0.2:__0
System.out.println("0.1:__"+Math.round(-0.4));// 输出0.1:__0
System.out.println("0.0:__"+Math.round(-0.5));// 输出0.0:__0
System.out.println("-0.1:__"+Math.round(-0.6));// 输出-0.1:__-1
System.out.println("-0.2:__"+Math.round(-0.7));// 输出-0.2:__-1
System.out.println("-0.3:__"+Math.round(-0.8));// 输出-0.3:__-1
System.out.println("-0.4:__"+Math.round(-0.9));// 输出-0.4:__-1
System.out.println("-0.5:__"+Math.round(-1.0));// 输出-0.5:__-1
System.out.println("-0.6:__"+Math.round(-1.1));// 输出-0.6:__-1
System.out.println("-0.7:__"+Math.round(-1.2));// 输出-0.7:__-1
System.out.println("-0.8:__"+Math.round(-1.3));// 输出-0.8:__-1
System.out.println("-0.9:__"+Math.round(-1.4));// 输出-0.9:__-1
System.out.println("-1.0:__"+Math.round(-1.5));// 输出-1.0:__-1
System.out.println("-1.1:__"+Math.round(-1.6));// 输出-1.1:__-2
System.out.println("-1.2:__"+Math.round(-1.7));// 输出-1.2:__-2
System.out.println("-1.3:__"+Math.round(-1.8));// 输出-1.3:__-2
System.out.println("-1.4:__"+Math.round(-1.9));// 输出-1.4:__-2
System.out.println("-1.5:__"+Math.round(-2.0));// 输出-1.5:__-2
System.out.println("-1.6:__"+Math.round(-2.1));// 输出-1.6:__-2
System.out.println("-1.7:__"+Math.round(-2.2));// 输出-1.7:__-2
System.out.println("-1.8:__"+Math.round(-2.3));// 输出-1.8:__-2
System.out.println("-1.9:__"+Math.round(-2.4));// 输出-1.9:__-2
相关推荐
而`Math.Round()`方法,在不指定舍入模式的情况下,会使用四舍六入五成双算法。例如: ```csharp Decimal de1 = 0.115M; de1.ToString("f2"); // 结果为: 0.12 Math.Round(de1, 2); // 结果为:0.12 (5 前为奇数,...
Math.round() 的取整规则是基于四舍五入的原理,即在参数上加 0.5 然后进行下取整。这种方法可以确保舍入结果尽可能接近原来的数字。 示例代码 以下是验证 Math.round() 的取整规则的示例代码: ```java int[] ...
在Java中,四舍五入可以通过多种方式实现,包括使用`Math`类中的方法以及`BigDecimal`类。 ### 使用Math类进行四舍五入 `Math`类是Java标准库的一部分,提供了多种数学函数,包括`floor()`和`ceil()`。这两个方法...
在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采用的是“四舍六入五成双”的方法,如下面的例子,就是用“四舍六入五成双”得到的结果: double d1 = Math.Round(1.25, 1);//1.2 double d2 = Math....
`Math.round()`方法是最具特色的,它执行“四舍六入五成双”规则,也称为银行家舍入法。对于非负数,它会根据小数部分来决定是否向最近的整数靠拢,遵循“四舍五入”的原则。对于负数,首先将其转换为正数,然后执行...