[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does bug 2921 justify a version 3.19.4?


Il 04/08/24 18:03, Benoît Minisini ha scritto:
Le 04/08/2024 à 13:56, Gianluigi a écrit :
Il 04/08/24 12:15, Christof Thalhofer ha scritto:
Hi,

I think so, because if Gambas in combination with PG doesn't count right
it can have ugly consequences.

Bug 2921: Postgresql 19.900000000000055 is 20 in Gambas

Alles Gute

Christof Thalhofer


Hi Christof and Benoit,

I'm referring to what is in question and Christof's comment on the
bugtracker  (Wow cool, thank you! The discussion even made me doubt my
own thinking. Good, that it's fixed!)
At this point I'm the one who's perplexed, I've always believed that to
manage the currency in Gambas it would be necessary to save the amounts
as integers, right?
How should numbers representing amounts be saved?

Thank you
Gianluigi


You should normally use an integer that will store your currency
multiplied by 10^N, N being the number of decimals you need.

You do that to avoid rounding errors when doing computations, or
printing currency (converting them to string).

You can use floating points, but you will be prone to rounding errors
with decimals, as 1/10 cannot be represented in binary.

Of course it makes the management a bit more complex when doing
conversion between currency and strings.

Regards,


Hi Christof and Benoit,

thank you both for the comforting answers on the use of integers (yes
even Christof's 'not necessarily' is comforting for me :-))

Even a small example, when possible, of how to process a 'Numeric'
number in Gambas would be of great help to me.

Regards
Gianluigi


References:
Does bug 2921 justify a version 3.19.4?Christof Thalhofer <chrisml@xxxxxxxxxxx>
Re: Does bug 2921 justify a version 3.19.4?Gianluigi <gradobag@xxxxxxxxxxx>
Re: Does bug 2921 justify a version 3.19.4?Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>