November 08, 2024, 04:57:07 PM

News:

IWBasic runs in Windows 11!


Doing Database money

Started by Brian, January 03, 2021, 09:32:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

January 03, 2021, 09:32:35 AM Last Edit: January 05, 2021, 10:13:28 AM by Brian
I have been messing about testing which would be the best data type to use with an MDB for money calculations, to avoid rounding errors
It does seem the way to do it is define your money field as CURRENCY in the MDB (which I honestly didn't think you could do), and then access it in IWB with a DOUBLE variable, and using SETPRECISION 2
Play with the code, and see the results of using CURRENCY, FLOAT and INT
I have used SETPRECISION 8 in this example, to show the rounding errors using FLOAT

Currency (I have read on the internet) is a data type that is called a scaled integer (so it is an integer value that ALSO stores the number of decimal places). These numbers are thus not floating point numbers but are stored as exact values along with a decimal placeholder

Brian

Edit: Slight speed modification

h3kt0r

Great ! Thank you for sharing the code.