Keep trailing zeroes in python

前端 未结 4 711
借酒劲吻你
借酒劲吻你 2020-12-18 22:43

I am writing a class to represent money, and one issue I\'ve been running into is that \"1.50\" != str(1.50). str(1.50) equals 1.5, and alll of a sudden, POOF.

4条回答
  •  無奈伤痛
    2020-12-18 23:46

    When working with money, always represent money using the Decimal class.

    http://docs.python.org/2/library/decimal.html

提交回复
热议问题