Kotlin Money

Languages and libraries

money library

SHOW HN2024

Legend

Kotlin Money

Manipulating monetary amounts is a common computing chore.

blog.eriksen.com.br

#kotlin#money#currency#bigdecimal#rounding

427points
228comments
#99of 3,515 in 2024
Top 3%of 2024 by points

How HN took it

CuriousMostly questions and neutral comments

8 positive, 43 neutral or asking, 1 mixed, 22 critical, out of 74 comments about the project. Thread score -0.14.

Design: 3 for, 15 againstIdea: 2 for, 7 againstExecution: 2 for, 0 against

The thread, comment by comment

Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.

positive neutral or mixed critical about another commenter or something else the maker

What HN said

What people liked

  • Useful API and good ergonomics compared to alternatives

    From 2 comments
    • Nice library! Manipulating money is probably trickiest thing since time was invented. Library looks very usable. I have to ask though: > val transactionFee = 1.25.percent() //…
      Ygg2 on HN
    • Nice. Looks like it satisfies all the requirements detailed here [0]. Also, good discussion of the major difficulty dealing with money here [1]. [0]…
      donjigweed on HN
  • Allocation feature is useful for splitting amounts

    From 1 comment
    • I just had to implement the 'allocate' functionality described here, specifically with the %-based weights, and it was a pain that required careful comments to ensure was clear!…
      monkaiju on HN

Objections

  • Too much infix notation makes the API hard to read

    From 3 comments
    • My only complaint is that there seems to be too much infix. Why not just do 50.btc, 25.3.usd This would keep it inline with the time API doing 20.seconds Also percentages could…
      Exerosis on HN
    • Infix functions is one of the worst features of Kotlin.
      wiseowise on HN
    • Kotlin has the problem of "I had N problems, so I think I can create 1 new solution, now I have N+1 problems" (obligatory https://xkcd.com/927/). The 'money/percent/usd' are…
      textlapse on HN
  • No support for cash rounding rules yet

    From 1 comment
    • This is something I am aware but there is no support for this rounding scheme at the moment.
      eriksencosta on HN
  • Prior art exists in Java Money, F# units of measure and other languages

    From 3 comments
    • Java has JSR 354 for money [1]. There is also a reference implementation [2]. So there is official support for money in Java. [1] https://jcp.org/en/jsr/detail?id=354 [2]…
      jsiepkes on HN
    • > no mainstream language has a first-class data type for representing money I don't think that's correct, absent some no-true-scotsman gymnastics. F# has units-of-measure (UoM)…
      psd1 on HN
    • C# has a decimal type: "The decimal type is a 128-bit data type suitable for financial and monetary calculations."…
      yett on HN

Requests

  • Cash rounding support

    From 1 comment
    • 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…
      Etheryte on HN
  • Localization of currency symbols

    From 1 comment
    • I like the support for custom currencies, as that is an edge case that often pops up. On the other hand, be careful about tying the symbol to the currency, as symbols are locale…
      bojanz on HN
  • Compile-time currency mismatch checks

    From 2 comments
    • Neat. It seems to me like this is filling three separate gaps: ``` - fixed point arithmetic - tagging values with units - localization for parsing currency names into units ```…
      rebeccaskinner on HN
    • I think most of this is covered by a good Decimal API, currency stuff probably shouldn't be embedded into a language because it changes: currencies come and go, get redenominated…
      boronine on HN

Questions

  • How does adding different currencies behave

    From 1 comment
    • I have questions about some edge cases I've encountered in dealing with money. - Let's say I load two money values from a database. Value A is 1 USD and value B is 1 BTC. If I…
      hathawsh on HN
  • How is rounding configured

    From 2 comments
    • I have questions about some edge cases I've encountered in dealing with money. - Let's say I load two money values from a database. Value A is 1 USD and value B is 1 BTC. If I…
      hathawsh on HN
    • Thanks for the questions. Answers: 1. You get an exception 2. You may specify the rounding rule: https://github.com/eriksencosta/money/blob/trunk/docs/usage/rounding.md 3. It has…
      eriksencosta on HN

Alternatives named

  • Java Money (JSR 354 / Moneta)

    From 2 comments
    • Java has JSR 354 for money [1]. There is also a reference implementation [2]. So there is official support for money in Java. [1] https://jcp.org/en/jsr/detail?id=354 [2]…
      jsiepkes on HN
    • How does it compare to the Java money API (https://jcp.org/en/jsr/detail?id=354) and the related Kotlin DSL in…
      hiddew on HN
  • F# units of measure

    From 1 comment
    • > no mainstream language has a first-class data type for representing money I don't think that's correct, absent some no-true-scotsman gymnastics. F# has units-of-measure (UoM)…
      psd1 on HN
  • C# and Delphi decimal/currency types

    From 2 comments
    • C# has a decimal type: "The decimal type is a 128-bit data type suitable for financial and monetary calculations."…
      yett on HN
    • Delphi has a currency type, as does C++Builder (so, a native Currency type available in C++ with that toolchain.) This one seems to carry units, as in, it is not a type with math…
      vintagedave on HN

Category, keywords, summaries and labels on this page were made by AI (Thread Reader v2) and not checked by hand. Each point links to the comments it came from.

Add a badge to your READMEShown on HackerShow
[![Shown on HackerShow](https://hackershow.org/badge.svg)](https://hackershow.org/show/41776878)