473,397 Members | 1,950 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,397 software developers and data experts.

Database (DB) is rounding incorrectly

I am new with access database and our database having rounding issues can any one help me here is the Query.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComputeInvoice(ciArg As String)
  2.     If IsNull(Me.[CustomerID]) Then
  3.       MsgBox ("Customer ID required!")
  4.       Exit Sub
  5.     End If
  6.     Dim SUBTOTAL As Double
  7.     Dim MATERIALCOST As Double
  8.     Dim HOURSTOTAL As Double
  9.     Dim TAX As Double
  10.     Dim MyDB As Database, MyRS As Recordset
  11.     Set MyDB = DBEngine.Workspaces(0).Databases(0)
  12.     Set MyRS = MyDB.OpenRecordset("tblcustomers", dbOpenTable)
  13.     MyRS.Index = "CustomerID"
  14.     MyRS.Seek "=", Me![CustomerID]
  15.     Me![CustomerID] = MyRS![CustomerID]
  16.     Me!LABORRATE = MyRS![LABORRATE]
  17.     MyRS.Close
  18.  
  19.     SUBTOTAL = 0
  20.     MATERIALCOST = 0
  21.     HOURSTOTAL = 0
  22.     'MsgBox Val(materialcost)
  23.     If Not IsNull(Me![MAT1]) Then MATERIALCOST = MATERIALCOST + Me!MAT1
  24.     If Not IsNull(Me![MAT2]) Then MATERIALCOST = MATERIALCOST + Me!MAT2
  25.     If Not IsNull(Me![MAT3]) Then MATERIALCOST = MATERIALCOST + Me!MAT3
  26.     If Not IsNull(Me![MAT4]) Then MATERIALCOST = MATERIALCOST + Me!MAT4
  27.     If Not IsNull(Me![MAT5]) Then MATERIALCOST = MATERIALCOST + Me!MAT5
  28.     If Not IsNull(Me![MAT6]) Then MATERIALCOST = MATERIALCOST + Me!MAT6
  29.     If Not IsNull(Me![MAT7]) Then MATERIALCOST = MATERIALCOST + Me!MAT7
  30.     If Not IsNull(Me![MAT8]) Then MATERIALCOST = MATERIALCOST + Me!MAT8
  31.     If Not IsNull(Me![MAT9]) Then MATERIALCOST = MATERIALCOST + Me!MAT9
  32.     If Not IsNull(Me![MAT10]) Then MATERIALCOST = MATERIALCOST + Me!MAT10
  33.     If Not IsNull(Me![MAT11]) Then MATERIALCOST = MATERIALCOST + Me!MAT11
  34.     If Not IsNull(Me![MAT12]) Then MATERIALCOST = MATERIALCOST + Me!MAT12
  35.     If Not IsNull(Me![MAT13]) Then MATERIALCOST = MATERIALCOST + Me!MAT13
  36.     If Not IsNull(Me![MAT14]) Then MATERIALCOST = MATERIALCOST + Me!MAT14
  37.     If Not IsNull(Me![MAT15]) Then MATERIALCOST = MATERIALCOST + Me!MAT15
  38.     If Not IsNull(Me![HOUR1]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR1
  39.     If Not IsNull(Me![HOUR2]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR2
  40.     If Not IsNull(Me![HOUR3]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR3
  41.     If Not IsNull(Me![HOUR4]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR4
  42.     If Not IsNull(Me![HOUR5]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR5
  43.     If Not IsNull(Me![HOUR6]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR6
  44.     If Not IsNull(Me![HOUR7]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR7
  45.     If Not IsNull(Me![HOUR8]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR8
  46.     If Not IsNull(Me![HOUR9]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR9
  47.     If Not IsNull(Me![HOUR10]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR10
  48.     If Not IsNull(Me![HOUR11]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR11
  49.     If Not IsNull(Me![HOUR12]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR12
  50.     If Not IsNull(Me![HOUR13]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR13
  51.     If Not IsNull(Me![HOUR14]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR14
  52.     If Not IsNull(Me![HOUR15]) Then HOURSTOTAL = HOURSTOTAL + Me!HOUR15
  53.     Me!totalmaterial = Round(MATERIALCOST, 2)
  54.     Me!totalhours = Round(HOURSTOTAL, 2)
  55.  
  56.     Me!totalcost = Round(HOURSTOTAL * LABORRATE, 2)
  57.     SUBTOTAL = Round((HOURSTOTAL * LABORRATE), 2) + MATERIALCOST
  58.     If Me!TYPE = "LR" Then Me!totalhours = Round((HOURSTOTAL * 1.5), 2)
  59.     If Me!TYPE = "LR" Then Me!totalcost = Round((HOURSTOTAL * 73), 2)
  60.  
  61.     If Me!TYPE = "LR" Then SUBTOTAL = Round((HOURSTOTAL * 73), 2) + MATERIALCOST
  62.  
  63.  
  64.  
  65.     TAX = 0
  66.     Me!invoicetotal = SUBTOTAL + TAX
  67.  
  68. If ciArg = "C" Then
  69.   Exit Sub
Can any one tell me when i add to total why my total is wrong like one digit up or down.
Dec 28 '07 #1
4 1582
Motoma
3,237 Expert 2GB
Hi portsamerica,
Perhaps you could tell us what language you are writing this in, as well as the database you are using. Also, give us a general sense of where the error is occurring. List any debugging methods you have tried, as well as your thoughts on their results.
Dec 28 '07 #2
this is MS ACCESS 2003 database and i never work on it.my boss want me to look in to that and fix the rounding issue.
Dec 28 '07 #3
NeoPa
32,556 Expert Mod 16PB
Please tell us which item is rounding incorrectly.
What type of field is used for the item?
Jan 2 '08 #4
FishVal
2,653 Expert 2GB
Take a look at the thread Round function - how it REALLY works

Regards,
Fish
Jan 2 '08 #5

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

Similar topics

18
by: Colin Steadman | last post by:
My ASP page allows user to enter comments into a form. To avoid errors I'm having to strip out double quotes before saving to the database. Is there anyway to encode these so that I can store...
5
by: news | last post by:
Well, I wrote my first PHP class today. Yeah! But to get it to work, in each function within the class I have to repeat the database connection lines, and that just seems redundant; there has to...
7
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when...
2
by: Roger Cantillo | last post by:
Hi, I'm using oleDBConnection to connect to SQL server. I keep getting "SQL Server does not exist" on Open event. The code I'm using is the following Dim objConn As New...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
6
by: John | last post by:
Hi Are there any RAD apps to speed up one-many db application development that are worth considering? Thanks Regards
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.