Comment by abdullahkhalids

Comment by abdullahkhalids 10 months ago

10 replies

How would this handle Canadian guidelines for dealing with cents in cash, where you round to the nearest 5c [1]?

    Amounts ending in 1 cent and 2 cents are rounded down to the nearest 10 cents;
    Amounts ending in 3 cents and 4 cents are rounded up to the nearest 5 cents;
    Amounts ending in 6 cents and 7 cents are rounded down to the nearest 5 cents;
    Amounts ending in 8 cents and 9 cents are rounded up to the nearest 10 cents;
    Amounts ending in 0 cent and 5 cents remain unchanged.
EDIT: I think if you send 12 cents,

    send [CADCASH/2 12] ( source = @user1 destination = @user2 )
It should result in sending 10 cents.

    "postings": [{"source": "user1",
                  "destination": "user2",
                  "amount": 10,
                  "asset": "CADCASH/2"}]
Can this happen?

[1] https://www.canada.ca/en/revenue-agency/programs/about-canad...

superzamp 10 months ago

Well that's definitely a good puzzle. I've tried to model it for a bit, but it indeed looks like we'd need to add something to the language to make it possible at all! Thanks for bringing this up.

  • fallat 10 months ago

    Same thing with income tax brackets. You need conditional logic.

    • superzamp 10 months ago

      For this particular case, I would say that tax-brackets sort of logic can be expressed in the destination block with ordered destinations.

      For example, you could have something like this:

          send [USD/2 *] (
            source = @users:1234
            destination = {
              // first $1000 are taxed at 10%
              max [USD/2 100000] to {
                10% to @taxes
                remaining kept
              }
              // Anything above that is, taxed at 20%
              remaining to {
                20% to @taxes
                remaining kept
              }
            }
          )
      
      (You can test it on the playground, you'll just want to feed the "users:1234" account with an initial balance in the input section)
euroderf 10 months ago

The rules listed (1,2,6,7 round down; 3,4,8,9 round up). AFAIK these are also the official Eurozone cash rules for countries that choose not to circulate 1 and 2 eurocent coins. (Altho of course, electronic transactions are exact to the penny.) So you might want to cover this use case.

  • o-o- 10 months ago

    So basically Math.round((x*20))/20?

    • Silphendio 10 months ago

      Shouldn't it be `round(x/5)*5` ?

      • shiandow 10 months ago

        Depends, are you working in cents or whole euros/dollars?

        • falcor84 10 months ago

          In all use-cases I encountered, working with integer cents is much cleaner than decimals

wombatpm 10 months ago

I’m assuming there are guidelines as to when this conversion happens and how often. Must make itemized invoices lots of fun. Specially when you have returns or cancellations

  • abdullahkhalids 10 months ago

    This pretty much only happen when you buy something at checkout. Your printed bill says total comes to CAD 5.12, you pay CAD 5.10 in cash. If you do a return, they will return in cash as well, and pay you CAD 5.10, because of the above rules.