News for hackers. Stuff that matters.
Re:DEC64: Decimal Floating Point by usr1106 on Sunday March 04, 2018 @06:45AM (#16514366)

  .getcontext().prec = 6
makes no sense for money. You need 2 digits after the decimal point constantly, whether it is 0.01 or 1000000.01

AFAIK (and I don't do this for work), after every calculation you manually need to call quantize as in

  cents = decimal.Decimal('.01')
  money = price.quantize(cents, decimal.ROUND_HALF_UP)
Re:DEC64: Decimal Floating Point by the-dude on Sunday March 04, 2018 @08:05AM (#16514563)
How would you handle prices for components which do have more significant digits than 2? ( I have examples if you wish ).
Re:DEC64: Decimal Floating Point by usr1106 on Sunday March 04, 2018 @11:11AM (#16515173)
Of course more digits than 2 exists. In Germany petrol/gas has always been priced with 3 decimals. And in B2B it's even more common. I'm talking about 98% of consumer business where the precision is full cents for each transaction.

In general you need to know when to round and to how many digits. But my complaint was that languages have a natural API for binary floating point, which is useful for scientific number crunching, but rarely anything comparable for commercial calculations.

I have not tried to design a natural API for fixed (but parameterizable) decimal precision and the implicit rounding required. But I would be surprised if it's impossible to come up with anything less verbose (explicit constructors everywhere) and less error prone (forgetting to call rounding).

Re:DEC64: Decimal Floating Point by sadiuasdi67f678 on Sunday March 04, 2018 @07:52AM (#16514533)
I'm not talking about money, I am talking about the decimal data type, as is OP.

https://en.wikipedia.org/wiki/Decimal_data_type

Also, I don't try to endorse the Python API. I don't even use it. I just pointed out their api is easier since the operators work with their decimal data type, as opposed to the Java version.