473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Double datatype comparison in VBA

67 64KB
Hi,

I have one issue that I don't understand. In my table I have fields like total, jan, feb, mar, apr, may,...,dec and all these fields I set its datatype as double and precision as auto.

In my form, I have use before update action to each input text box with condition as :

Expand|Select|Wrap|Line Numbers
  1. if(nz(me.jan,0)+nz(me.feb,0)+nz(me.mar,0)+nz(me.apr,0)+nz(me.may,0)+nz(me.jun,0)+nz(me.jul,0)+nz(me.aug,0)+nz(me.sep,0)+nz(me.oct,0)+nz(me.nov,0)+nz(me.dec,0)) >me.total then msgbox "exceed total" 
when I insert with these data :
total=15080
jan=feb=mar=0
apr=1072.96
may=2602.958
jun=2628.958
jul=2504.958
aug=2504.958
sep=2505.958
oct=1160.25
nov=99

it suddenly popup message "exceed total" when I input 99 to nov text box. But when I use msgbox to popup each value and its sum, it is 15080.

Could anybody tell me how to compare double datatype ?

Sophanna
Mar 30 '14 #1
5 2719
Rabbit
12,516 Expert Mod 8TB
Double values are not exact. It will always be off by a small fraction. So your 1160.25 is probably 1160.2500000000001 or 1160.24999999999999. In your scenario, what you can do is convert the final number to an integer so the fractional part drops off before comparing it.
Mar 30 '14 #2
sophannaly
67 64KB
Hi Rabbit,

So it means that I should use Round function by giving it exact precision digit before comparing these two values. Is it?

Sophanna
Mar 31 '14 #3
NeoPa
32,556 Expert Mod 16PB
If you want to avoid rounding errors then you will need to round each element of the calculation to the number of decimals you require (probably 2). Alternatively, of course, use Currency or Number/Decimal for the fields in the first place to avoid such problems.
Mar 31 '14 #4
sophannaly
67 64KB
Hi NeoPa,

So may I ask that to store with such these data 342.45323, 43232343,234 Number/Decimal datatype is much better than double type. Is it?

Sophanna
Apr 2 '14 #5
NeoPa
32,556 Expert Mod 16PB
That rather depends on how you want to use it Sophanna. It seems you want to sum them together without rounding errors. That is certainly better with Number/Decimal.

Double is better when you have enormously large numbers that won't fit within a Number/Decimal, but frankly that's rare when dealing with currency values and calculations.
Apr 2 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: dotyet | last post by:
Hey All, I have a small problem. consider the following >db2 "create table ttt (mynum float, yournum double )" DB20000I The SQL command completed successfully. >db2 "describe table ttt" ...
1
by: L Mehl | last post by:
Hello -- Goal is to export data from tblData having this structure: dateRecord Date/Time textFrom Text 4 textTo Text 4 valueRecord Number Double (format = Standard, Dec Pl = 12)...
5
by: DAVID SCHULMAN | last post by:
I've been trying to perform a calculation that has been running into an underflow (insufficient precision) problem in Microsoft Excel, which calculates using at most 15 significant digits. For this...
4
by: David Veeneman | last post by:
Are System.Double operators overloaded to perform epsilon comparisons, or do these comparisons have to be performed by the programmer. In other words, if I have two doubles, A and B, and I test "A...
0
by: Kaja | last post by:
Hi, Compare validator throws error if I have thousand seperator in the double value. ControlToValidate: TextBox1 Operator: DataTypeCheck Type: Double Any help appreciated.
1
by: Savas Ates | last post by:
I have a column in my table BizdekiFiyat . The datatype = float length =8 (to save money values).. It is impossible to change these attributes for some reasons. It has records like This ...
8
by: abdul_n_khan | last post by:
Hello, I have a basic question related to datatypes. I am trying to read a value using Microsoft's ADO recordset from a field (lets call it 'Price') with datatype decimal(19,6) => 19 = Precision,...
14
by: cj | last post by:
VB2003. I need a large positive integer. Which is larger int64 or double? I see int64 also apparently is known as long and will hold -9,223,372,036,854,775,808 through...
2
by: Randy Smith | last post by:
Hi, Does anyone have any good techniques on how to convert an SQL Server 2005 "money" datatype into the ASP.Net "double" datatype? OR, should we be using "decimal" at both ends? TIA, Randy...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.