偶尔看到一个面试题,写的是round的理解,原来一直认为是四
舍五入,原来是这样的
Math.round()什么作用?
Math.Round(3.44, 1) = 3.4
Math.Round(3.45, 1) = 3.4
Math.Round(3.46, 1) = 3.5
-----------------------------------------------
Math.Round(3.54, 1) = 3.5
Math.Round(3.55, 1) = 3.6
Math.Round(3.56, 1) = 3.6
-----------------------------------------------
Math.Round(3.64, 1) = 3.6
Math.Round(3.65, 1) = 3.6
Math.Round(3.66, 1) = 3.7
-----------------------------------------------
Math.Round(3.74, 1) = 3.7
Math.Round(3.75, 1) = 3.8
Math.Round(3.76, 1) = 3.8
这种舍入方法叫做银行家舍入(Banker'sRound),这就是已经规定下来的标准、Round的标准、世界的标准。
Round <> 四舍五入