Working With Floats and Integers

前端 未结 7 785
旧时难觅i
旧时难觅i 2020-12-21 08:40

I\'ve created an ATM like program which holds the money in a person\'s account. When the person takes out a withdrawal, it subtracts the withdrawal from the account along wi

7条回答
  •  盖世英雄少女心
    2020-12-21 09:22

    You should probably use Binary Coded Decimals when dealing with money. It will allow you to use a single variable for both dollars and cents. While you are at it, you can specify a typedef struct union that will let you specify the value in dollars, cents, whole dollars only, and cents remainder only. Short of exchange with other currencies, that will be good for just about every monetary scenario.

提交回复
热议问题