[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Currency representation in Lua
- From: KHMan <keinhong@...>
- Date: Mon, 05 Sep 2016 12:04:11 +0800
On 9/5/2016 11:24 AM, Sean Conner wrote:
It was thus said that the Great Luiz Henrique de Figueiredo once stated:
Has someone any experience to share about implementing a system that deals
with currency values?
Express your amount in cents, not dollars (or euros or reais).
You can then use integers instead of floats.
It works even in Lua versions before 5.3
Just a quick question---is there a smaller unit than the Euro? Or Reais?
While I can't complain about using cents over dollars [1], I think there
might be some issue with currency conversion.
Some systems do need more precision than cents. Here is an example
from Newark/Element14 for a rather expensive SMD chip resistor (USD):
1+ $0.083
50+ $0.016
100+ $0.012
Switching currencies, here is another item in RM (Ringgit Malaysia):
1+ RM0.56 (RM0.5936)
10+ RM0.09 (RM0.0954)
100+ RM0.05 (RM0.053)
The number formatting does not look ideal, but it sure looks like
the values are exact. There are items on sale for $0.001, mostly
SMD chip resistors, I haven't seen a smaller price. I buy 100, the
total price becomes $0.10. But, uh, the shopping cart popup
reports $0.00 for unit price, someone messed up there.
I'm sure their Finance people and IT people are on top of this
thing... Whatever their database is using, it appears to be
dealing in exact values. But it does illustrate the complexities
of a website for global online sales where individual items can be
pretty cheap, pricing can be smaller than 1 cent, etc.
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia