Microsoft
Software
Hardware
Network
Question : How to use Decimal Data Type in VBA code
I need to record Purchase Order line item quantities to 2 decimal places. In the past I've always used a double data type and forced rounding to 2 decimal places in my forms. I've been toying with the idea of changing the table column from a double to a decimal datatype with a scale of 2 so that I don't have to do any rounding in my forms and have the jet engine take care of it for me at the table level. Since VBA doesn't support a decimal data type, how do I handle these values in code and avoid rounding problems?
For example if I have some code that nees to add decimal data type values, do I read each value into a variant as follows:
dim var1 as variant
dim var2 as variant
dim varSum as variant
var1 = 1.15
var2 = 1.85
varSum = cdec(var1) + cdec(var2)
How does VBA handle rounding in the above style code?
Or do I convert each value to a double and do the rounding myself:
dim dbl1 as double
dim dbl2 as double
dim dblSum as double
dblSum=MyRoundingFunction(
dbl1+dbl2,
2)
Answer : How to use Decimal Data Type in VBA code
rmk,
your'e right - point taken. I didn't verify this.
But, I still would use double. Just calculate with this type and before writing it to the table do a rounding with a custom function. This should be the easiest way.
Greetings
Andy
Random Solutions
What's netmask ?
array, init, qw - how to include empty string
After changing TCP/IP settings (IP from other IP range) windows firewall has switched the active profile from domain to standard. WHY ?
Once in a while I am receiving this Microsoft error ?
viewing actionscript within .fla file
Exchange 2003 no inbound and local delivery
Search Engine Registration
Exchange 2003 - Prevent Deletion of Email - Without use of Journaling
Set up a test environment for sharepoint server 2007
The 2003 Server Keeps Rebooting. 0x000000ba (0x00000002, 0x00000001, 0xeb953598, 0x0000001f)