The conversion between floating point and integer python

  • Discarding the decimal part  

    >>> math.trunc(12.533222)
    12   

    >>> round(12.2544)
    12

  • Rounded off by a given number of decimal places

    >>> round(12.2544, 3)
    12.254

  • Improvement ToSei

    >>> math.ceil(12.4584)

    13

  • Rounding down

    >>> math.floor(12.4584)

    12

Guess you like

Origin www.cnblogs.com/bryant24/p/11422660.html
Recommended