将精度高的浮点数转换成精度低的浮点数。git
这个是使用最多的,刚看了round()的使用解释,也不是很容易懂。round()不是简单的四舍五入的处理方式。函数
For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2).ui
round()若是只有一个数做为参数,不指定位数的时候,返回的是一个整数,并且是最靠近的整数(这点上相似四舍五入)。可是当出现.5的时候,两边 的距离都同样,round()取靠近的偶数,这就是为何round(2.5) = 2。当指定取舍的小数点位数的时候,通常状况也是使用四舍五入的规则,可是碰到.5的这样状况,若是要取舍的位数前的小树是奇数,则直接舍弃,若是偶数这 向上取舍。看下面的示例:ip
效果和round()是同样的。it
既然说到小数,就必然要说到整数。通常取整会用到这些函数:方法
这个不说了,前面已经讲过了。必定要注意它不是简单的四舍五入,而是ROUND_HALF_EVEN的策略。im
取大于或者等于x的最小整数。img
去小于或者等于x的最大整数。di