Decimals to 2 places for money in Python 3

后端 未结 5 910
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 05:26

How do I get my decimals to stay at 2 places for representing money using the decimal module?

I\'ve setting the precision, and damn near everything else

5条回答
  •  自闭症患者
    2020-12-15 05:53

    One way to solve this is to store money values in cents as integers, and only convert to decimal representation when printing values. This is called fixed point arithmetic.

提交回复
热议问题