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

rounding in access

I have a number 6.51495989352464 that I need to round to 6.51

I am using the following code:
Public Function MyRound(dblInput As Currency, intDecimal As Integer) As Double

If dblInput < 0 Then
MyRound = -Int(CDec((Abs(dblInput) * 10 ^ intDecimal) + 0.5)) / 10 ^ intDecimal
Else
MyRound = Int(CDec((dblInput * 10 ^ intDecimal) + 0.5)) / 10 ^ intDecimal
End If


End Function

When I step into the code what is actually going through the MyRound code is 6.515 so it makes sense that it is rounding to 6.52 but I do not know why it is rounding from 6.51495989352464 to 6.515.

It's probably very simple but I'm not seeing it.
Mar 8 '10 #1

✓ answered by ziccardi

I changed dblInput As Currency to dblInput As Double ... it seems to work now

5 2012
one other wierd quirk: for some reason the code is multiplying
( 210.16 ) * ( 3.09999994933605E-02 )
it should be multiplying
( 210.16 ) * ( 0.0310)

I know it's not much of a difference but the 0.0310 is being pulled directly from a table where the field is defined as Number-Single-Fixed (4 decimal places)

Thanks!
Mar 8 '10 #2
gershwyn
122 100+
Have you tried using the built in round function?

Expand|Select|Wrap|Line Numbers
  1. Round(6.51495989352464, 2)
=6.51
Mar 8 '10 #3
The built in round function in Access uses Banker' Rounding logic. Banker's rounding rounds .5 up sometimes and down sometimes.

I need it to be Symmetric arithmetic rounding where it rounds .5 away from 0. Similar to Excel Worksheet Round function.

Besides it seems to be rounding correctly but it looks like the number is being rounded before it even gets to my rounding code. I am going to try changing dblInput to Double in the code and see if that corrects it.
Mar 8 '10 #4
ADezii
8,834 Expert 8TB
The result that I am getting is 6.52, namely:
Expand|Select|Wrap|Line Numbers
  1. Public Function MyRound(dblInput As Currency, intDecimal As Integer) As Double
  2.   If dblInput < 0 Then
  3.     MyRound = -Int(CDec(Abs(dblInput) * (10 ^ intDecimal)) + 0.5) / (10 ^ intDecimal)
  4.   Else
  5.     MyRound = Int(CDec(dblInput * (10 ^ intDecimal)) + 0.5) / (10 ^ intDecimal)
  6.   End If
  7. End Function
Expand|Select|Wrap|Line Numbers
  1. Debug.Print MyRound(6.51495989352464 ,2)
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. 6.52
Mar 8 '10 #5
I changed dblInput As Currency to dblInput As Double ... it seems to work now
Mar 8 '10 #6

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

Similar topics

3
by: Dalan | last post by:
Is there any code available to address currency rounding problems in Access 97? Apparently, selecting currency type table fields does not resolve the problem. For instance, in my form I have a...
1
by: Mike MacSween | last post by:
This looks like a bug to me. I have an expression on a report: =Format(Sum((**)*(/)),"0.00") Score is byte PercentOfGrade is double PropDegree is single ModuleCats is byte
2
by: Lynn N. | last post by:
I have a report showing Rate, Hours and Total Pay (which is Rate*Hours) for several workers. I want to sum the Total Pay and get a CORRECT figure. This seems like it should be such a simple task....
6
by: DaveK | last post by:
I am upgrading an MS Access 97 application which uses the format function to round decimal numbers to two places e.g. format(dblValue, "standard") Having done an initial study of this...
13
by: dhildebrandt | last post by:
I have a query that uses the Round function to change decimals into whole numbers. For 4 years straight the thing has always rounded the numbers in exactly the same way so that whenever I update...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
6
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, I'm using the following on a form in my database: =(-Int(-Sum((IIf(=Yes,((*)+()), (((*)+)*1.06))*100))))/100 In this case, I want to calculate a total for an order. If...
3
by: gabo22003 | last post by:
Hello, I've inherited a tax report where all of the financial numbers are currency.This is a detailed report that lists amount, tax and total for that day ( total is listed in the database). The...
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) ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.