2 ms·
> However, no mainstream language has a first-class data type for representing money... I beg to differ. Java has "Decimal" class which guarantees to be safe f
by bayindirh 2y ago
> However, no mainstream language has a first-class data type for representing money...
I beg to differ. Java has "Decimal" class which guarantees to be safe from IEEE754 floating number side effects, and specially created to handle cases like money and financial calculations.
In these days it's used as BigDecimal, it seems [1].
[0]: https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html https://docs.oracle.com/javase/8/docs/api/java/text/DecimalF...
[1]: https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/math/BigDecimal.html https://docs.oracle.com/en/java/javase/23/docs/api/java.base...
- jeremyjh 2y agoCan BigDecimal tell me which currency a monetary value is denominated in?
- bayindirh 2y agoNo, but Java has a specification (JSR 354) to build money and currency APIs [0]. A library built upon it can be found here [1]. [0]: https://jcp.org/en/jsr/detail?id=354 https://jcp.org/en/jsr/detail?id=354 [1]: https://javamoney.github.io/ https://javamoney.github.io/
- deleted 2y ago[deleted]
- mhluongo 2y agoTell me you've never worked in fintech without telling me you've never worked in fintech :) Decimals aren't enough. You have frequent currency conversions and all sorts of other chores. Using a fixed-decimal datatype doesn't solve those problems by itself, it's just a tactic.
- bayindirh 2y agoSee JSR-354 then: https://jcp.org/en/jsr/detail?id=354 https://jcp.org/en/jsr/detail?id=354 Yes, I never worked in fintech, but lots of my family members work or worked in banking sector. So, I'm not an alien when it comes to money, and how it works and processed in IT side of the things.