How do I Match the rounding in Access (query) that was in Excel
I am using a query to create formulas to calculate percentages as well as reimbursement amounts in Access. Calculations were originally done in Excel, but data is stored in Access, so decided to use Access to calculate as well. Unfortunately, Acccess not rounding as in Excel.
For example 42 / 64 =.65625
in Excel displays as .6563 rounding to 4 decimal places,
in Access displays as .6562 rounding to 4 decimal places.
As stated, these must be exact calculations and are finding differences in Access vs. Excel.
Function RoundUp(ByVal Number As Variant, ByVal Places As Integer) _
As Double
Dim dblTemp As Double
dblTemp = CDec(Nz(Number))
dblTemp = CDec(dblTemp * 10 ^ Places)
RoundUp = Fix(dblTemp + 0.5 * Sgn(Number)) / 10 ^ Places
End Function
Your solution appears to have corrected most of my issues, except one.
I must round all formulas to 4 decimal places when possible.
There are 4 variables ie: A+B+C=D (these variables are field names)
A is / by D and must round giving 4 decimal place answer.
B is / by D and must round giving 4 decimal place answer.
same for C
I have one record where A = 26, B =6 and C =47 making D= 79
When dividing B by D, [ 6 / 79 ] answer shows as .076, which i need to display as .0759 to calculate properly.
How can i adjust this so that all other records, which appear to calculate correctly, do not change. this is the only record now not calculating properly.
Once again, this is done in a query, that I must export to excel for further calculations.
Not able to send file, information confidential. But not returning result of .2213. There are several calculations that take place in this query. all using your Format command to round out decimal places and not consistent in the rounding. This information is sent to the state and must be accurate before sending.
Well, if you can't or won't tell us what you are doing, it is rather difficult to help.
The expression using Format will and does work. In fact, it is the simplest (though not the fastest) proven method in VBA to perform correct 4/5 rounding under any condition:
Attached are 2 files. Excel is where the correct calculations reside that i must use. The data actually resides in a database, therefore, thought we should use be able to use access to do the calculations also. Problem is the rounding is not exact. This example : Little Leaders of Tomorrow on Excel rounds to .2213, in access rounds to .2212. Is doing eventhough I used the CDbl(Format),"0.0000"))
Found this information online.... demonstrates my problem..... How can I make the VBA Round function behave like the Excel Round function as demonstrated in the link above?
The reason is that in your USDA table, data type Single is used throughout.
Therefore, when casted to double, 1.18 resolves to 1.17999994754791 which is smaller than 1.18, thus your rounded value ends up slightly smaller.
So, change all fields to data type Double and reentry your values.
/gustav
0
softsupportAuthor Commented:
Geez..... thank you for the assistance. Pulled my hair out looking for the answer and needed additional eyes to locate the problem. Much appreciation !
With monday.comâ€™s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.