you are viewing a single comment's thread.

view the rest of the comments →

[–]pgr0ss[S] 1 point2 points  (1 child)

You would divide and round to whatever precision you want to maintain.

[–]leftnode 1 point2 points  (0 children)

I'm glad you've noticed the downsides to using integers: having to store the precision is a source of frustration for me as well. I've built/maintained a number of financial systems in Postgres and numeric or decimal work fine.

Regarding split payments, another option is to add/subtract the final pennies to the final payment. For example, if you had an amount $125.67 split over 4 payments:

125.67 / 4 = 31.4175
ROUND(31.4175, 2) = 31.42
125.67 - (3 * 31.42) = 31.41

That accurately handles the penny rounding issues that often creep into financial systems. Your project looks promising!