[Gambas-user] Float hidden precision?
rwe-sse at osnanet.de
Wed Nov 18 08:25:55 CET 2020
Am 17.11.20 um 13:47 schrieb KKing:
> Is it possible for a float variable to have unwanted hidden distortion
> in a held value?
> I have a conundrum buried in a lot of code but essentially I have two
> monetary values which originally arrive as strings in a csv file.
> I then convert these to float values for other processing but by
> debugging I have come across the following issue where essentially the
> value has been distorted.
A similar problem came up for me some years ago. As the others proposed,
I convert these strings into integers, using cent values only. You could
even use tenth of cents to meet commercial standards.
You can write yourself some handy functions that do the conversion into
integer and from cents back to currency strings the way you need it for
your locale. Another way might be Format - but I never needed to dive
into that one, so I know little about it.
More information about the User