python浮点数与整数间的转化

  • 舍弃小数部分  

    >>> math.trunc(12.533222)
    12   post

    >>> round(12.2544)
    12blog

也能够:class

int(12.0)=12di

 

 

  • 按给定小数位数四舍五入

    >>> round(12.2544, 3)
    12.254math

  • 向上取整

    >>> math.ceil(12.4584)

    13

  • 向下取整

    >>> math.floor(12.4584)

    12

相关文章
相关标签/搜索