News for hackers. Stuff that matters.
Re:Kotlin Money by Etheryte on Tuesday October 08, 2024 @09:36AM (#41777232)
Does this library handle rounding rules [0]? In many countries, prices are rounded to the nearest 5 cent, but the rules can often be elaborate. It looks like the allocation interface might support this, but at the moment I didn't find any mention of it without digging into the docs themselves.

[0] https://en.wikipedia.org/wiki/Cash_rounding

Re:Kotlin Money by graypegg on Tuesday October 08, 2024 @09:56AM (#41777429)
I think one common feature of those rounding procedures is that they are only done for cash payments, rather than plastic, so rather than representing a monetary value, it would have to represent a payment specifically. (With knowledge of payment method and time of transaction since a lot of these rules had a start date.) Possibly a good library to extend off of this!
Re:Kotlin Money by eriksencosta on Tuesday October 08, 2024 @09:45AM (#41777318)
This is something I am aware but there is no support for this rounding scheme at the moment.
Re:Kotlin Money by amluto on Tuesday October 08, 2024 @09:52AM (#41777391)
Wait, how do you round? A fixed table from currency to minimum increment? You’re not about to find 1/100-Yen coins, for example.
Re:Kotlin Money by vetinari on Tuesday October 08, 2024 @10:05AM (#41777514)
You are not going to find 1 or 2 eurocents anymore either, but it is still a valid amount. You can pay that electronically, but not in cash.

So rounding for cash is a different problem that rounding money in general.

Re:Kotlin Money by sigh_again on Tuesday October 08, 2024 @12:09PM (#41778927)
>You are not going to find 1 or 2 eurocents anymore either

You may want to tell that to my wallet, as well as the payments I make with them. There's a cool 37 billion coins outside in the wild, so you're going to find them rather easily throughout Europe, even if your own country has stopped using them.

Re:Kotlin Money by cyxxon on Tuesday October 08, 2024 @10:20AM (#41777680)
Huh? 1 and 2 eurocents have not been deprecated, afaik only Finland and the Netherlands don't use them anymore...
Re:Kotlin Money by vetinari on Tuesday October 08, 2024 @11:04AM (#41778126)
Also Belgium, Ireland, Italy, Slovakia...

Technically, you can use them for payment, they are still valid money; but the price will be rounded to 5 cents when paying in cash and you won't get them in the other direction.

Re:Kotlin Money by jeroenhd on Wednesday October 09, 2024 @02:51AM (#41785203)
The 1 and 2 eurocent coins are still legal tender in the Netherlands, stores just have the option not to accept them and are allowed to round prices to avoid having to stock them (if communicated beforehand).

It's been years since I last saw a eurocent coin, but it's been eliminated by permitting businesses to remove the need for them, not because they're being phased out.

Re:Kotlin Money by criddell on Tuesday October 08, 2024 @09:58AM (#41777456)
Things like gasoline can have a price that is a fraction of a cent. The ultimate price is rounded.

Canada has these guidelines: https://www.canada.ca/en/revenue-agency/programs/about-canad...

Re:Kotlin Money by eriksencosta on Friday October 11, 2024 @01:18AM (#41806405)
HALF_EVEN by default using the minor units of each currency (based on CLDR/ICU datasets). Client code can disable rounding at all.

Check for more: https://github.com/eriksencosta/money/blob/trunk/docs/usage/...

Re:Kotlin Money by sernamar on Tuesday October 08, 2024 @05:27PM (#41781995)
I'm working on a Clojure library for working with money [0] that handles specific rounding rules by passing a custom rounding function to the round function, allowing you to specify different rules as needed.

There's an example for the Swiss Franc in the README (the code is here [1]).

[0] https://github.com/sernamar/dinero

[1] https://github.com/sernamar/dinero/blob/main/src/dinero/roun...