For accounting program I need to divide a price by 3 so it can be shared over 3 months
For example 9€
Now this would be price/3
But what if the number is 10?
3,33€*3 =€9.99
One cent has gone missing. How can I make it so the ouput would become 3,33€ , 3,33€ , 3,34€?
You need to ask the accountant what they would want here. That's an important thing to do in software development: ask the users.
Normally, for stability, you would subtract the amounts paid from a balance account, and put checks in to ensure that the balance falls to zero.
And don't ever use a floating point data type when building accounting software. Floating point precision will bite you. Use a currency type instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With