On 23 December 2020 at 0:25, Thomas Lenherr said: > Thank you all for your responses. > > For the record, this is for private bookkeeping purposes (mainly splitting > costs for different things with roommates), and so regulations generally > don't apply as accuracy to a cent is more than enough and I mostly just > want to prevent having to fix imbalances often. Having done this for the > past ~12 years, for anything between 5-10 monthly transactions, I was > hoping to automate this ever so slightly more, as is the trend with > software. > > Given the late rounding, somebody mentioned the idea earlier that adding > or subtracting 0.005 could be used to turn the "normal rounding" into > either "rounding up" or "rounding down", I haven't tested that yet, but I > suspect that could work, at least as long as the amount only has be split > between two parties: > > my_expense_amount = (total_amount / 2) # Normal rounding > roommates_expense_amount = (total_amount / 2) - 0.005 # Rounding down
No, you have it backwards (at least when the quotient is truncated, i.e. rounded down, as seems to be the case): winner = (total+0.01)/2 (or, equivalently, winner = total/2 + 0.005) loser = total/2 > This is a little messier than I hoped and only works well when splitting > two-ways (when you do 3+-ways it gets a little trickier). I was wondering > if any devs here could comment on the options to rather supporting a > function to explicitly trigger the rounding early, that way the above > could e.g. be written as: > > roommates_expense_amount = (total_amount / 2) # Or really any fraction > could work with this my_expense_account = total_amount - > roommates_expense_amount = total_amount - gnc_round(total_amount / 2) > > I'm aware that custom functions can be added to fin.scm, but I didn't dig > deep enough yet to understand how I could explicitly trigger the > rounding-step from there, if at all. Plus it seemed like there's a slim > chance this could be a useful function to include by default since gnucash > doing rounding is an omnipresent operation. The only difficult bit about sharing among three is deciding how to distribute the odd amounts. Exactly as with dividing by two. winner2 = (total+0.02)/3 winner1 = (total+0.01)/3 loser = total/3 _______________________________________________ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information. ----- Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.