Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren, 6 Monaten
Letzter Beitrag:
vor 2 Jahren, 6 Monaten
Beteiligte Autoren:
Curtis, Fabrice Harari, Allard

[WD20] 0.10 in Db becomes 0.1000000014901[SOLVED]]

Startbeitrag von Curtis am 17.12.2015 15:11

I have a tax rate stored as a 4 byte real. The tax rate is 0.10. When I query the Db and insert the tax rate into a table column the rate becomes 0.1000000014901. I've tried just about every Numeric input mask includingg 4 byte real. What's going on?

Also - I made sure that no other code is effecting this value. Right after TableAddLine() I did a trace to make sure the value was 0.1000000014901.


Re: [WD20] 0.10 in Db becomes 0.1000000014901


I had something similat in a windev application when doingcalculations.

You can use this in your calculation

ROUND( calculation, 2 ) this is goning to round to two decimals.


von Allard - am 17.12.2015 15:16

Re: [WD20] 0.10 in Db becomes 0.1000000014901

I thought about that, but since I'm dealing with sales I need everything to be perfect. Also I want to allow tax rates up to 4 decimals.

von Curtis - am 17.12.2015 15:31

Re: [WD20] 0.10 in Db becomes 0.1000000014901


this is unfortunately absolutely normal. Reals are a very OLD type of variable, created at the time where every byte counted. So the internal storage format does not allow to store every EXACT value.

This is why we have both the Currency and Numeric variable types, and you should use one of those two ALL the time, instead of reals, if you want to store/use EXACT value.

By the way, this is not a windev thing. Reals are a universal format and exhibit the same behavior in all languages.

Best regards

von Fabrice Harari - am 17.12.2015 15:36

Re: [WD20] 0.10 in Db becomes 0.1000000014901

Thanks guys.
Thanks Fabrice.

von Curtis - am 17.12.2015 16:00
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.