Limiting floats to two decimal points

前端 未结 28 3210
你的背包
你的背包 2020-11-21 04:57

I want a to be rounded to 13.95.

>>> a
13.949999999999999
>>> round(a, 2)
13.949999999999999

The ro

28条回答
  •  感情败类
    2020-11-21 05:20

    float_number = 12.234325335563
    round(float_number, 2)
    

    This will return;

    12.23
    

    round function takes two arguments; Number to be rounded and the number of decimal places to be returned.Here i returned 2 decimal places.

提交回复
热议问题