Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dividing prices by 3

Tags:

c#

math

numbers

For accounting program I need to divide a price by 3 so it can be shared over 3 months

For example 9€

  • 3€ first month
  • 3€ second month
  • 3€ third month

Now this would be price/3

But what if the number is 10?

  • 3,33€ first month
  • 3,33€ second month
  • 3,33€ last month

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€?

like image 491
Boyen Avatar asked Feb 20 '14 16:02

Boyen


1 Answers

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.

like image 163
Bathsheba Avatar answered Oct 14 '22 09:10

Bathsheba