Truncate to three decimals in Python

后端 未结 20 2540
故里飘歌
故里飘歌 2020-11-27 06:20

How do I get 1324343032.324?

As you can see below, the following do not work:

>>1324343032.324325235 * 1000 / 1000
1324343032.3243253
>>i         


        
20条回答
  •  孤街浪徒
    2020-11-27 06:33

    Maybe python changed since this question, all of the below seem to work well

    Python2.7

    int(1324343032.324325235 * 1000) / 1000.0
    float(int(1324343032.324325235 * 1000)) / 1000
    round(int(1324343032.324325235 * 1000) / 1000.0,3)
    # result for all of the above is 1324343032.324
    

提交回复
热议问题