python中金額計算的小問題

因爲二進制對浮點運算存在精度問題,因此一些浮點計算常常會出現如下狀況:html 1 # -*- coding: utf-8 -*- 2 3 a = 1 4 b = 0.9 5 print(a-b) 結果:python 0.09999999999999998 咱們指望的結果應該是0.1。爲了解決這個問題,能夠引入python的decimal庫:post 1 # -*- coding: utf-8
相關文章
相關標籤/搜索