How do I stop rounding of my calculation results.

W

Weeble

I have a calculation that is being rounded, much to my dismay.

I tried setting the decimal places to 2 in the table and yet my results are
still rounded to the nearest whole number. I don't know how to fix this
problem.

Please help.
 
D

Douglas J. Steele

What's the data type of the field in question? The default data type for
Numeric fields is Long Integer, which by definition do not have any decimal
points. You need to insure that you're using a data type that supports
decimal points: Single, Double, Decimal or Currency.
 
W

Weeble

Thank you. That took care of that one for me. However, I am having the same
issue with an unbound control on a form. It displays the result of a
calculation that is for informational purposes only and will not be stored at
this time. I have chosen a format that displays 2 decimal places and I have
specified 2 decimal places but it too is rounding to the nearest whole
number. I look for something like you told me about for the table but found
nothing.

Any ideas?
 
W

Weeble

Douglas,

Here is a sample of the code that I am using to calculate a bonus amount:


If Qnty >= 600 And Qnty <= 699.99 Then
BnsAmnt = 0.25
ElseIf Qnty <= 799.99 Then
BnsAmnt = 0.5
ElseIf Qnty <= 899.99 Then
BnsAmnt = 0.75
ElseIf Qnty <= 999.99 Then
BnsAmnt = 1

If the amount is less that 0.51 my control is rounding down to 0. If the
amount is 0.51 or greater it is rounding to 1.

The control is set to a "Currency" format with the decimal places set to 2.
I don't know what else to look at.

The calculations are being made in a module and being shown in an unbound
control on a form. I will not be storing this data at this time but it will
become important later as I complete my project.

Any help would be greatly appreciated. Thanks.
 
D

Douglas J. Steele

You show a calculation, but not how that calculation is assigned to the
control. How are you doing that?
 
B

Bob Quintal

Douglas,

Here is a sample of the code that I am using to calculate a bonus
amount:


If Qnty >= 600 And Qnty <= 699.99 Then
BnsAmnt = 0.25
ElseIf Qnty <= 799.99 Then
BnsAmnt = 0.5
ElseIf Qnty <= 899.99 Then
BnsAmnt = 0.75
ElseIf Qnty <= 999.99 Then
BnsAmnt = 1

If the amount is less that 0.51 my control is rounding down to 0.
If the amount is 0.51 or greater it is rounding to 1.

The control is set to a "Currency" format with the decimal places
set to 2. I don't know what else to look at.

The calculations are being made in a module and being shown in an
unbound control on a form. I will not be storing this data at this
time but it will become important later as I complete my project.

Any help would be greatly appreciated. Thanks.
In the module, usually right below the module declaration, you need
to declare the variable and set it to 0.

Dim BnsAmnt as double
BnsAmnt = 0

Also, your test for >= 600 is not logical. Say Qnty = 500.
the If rejects it (>=600), so the code moves to the first ElseIf,
which accepts it, because it does not know about the lower limit in
the statement above..

you can either move the first test to a separate line
If Qnty < 600 Then
' do nothing
ElseIf Qnty < 700 then
BnsAmnt = 0.25
etc
 
W

Weeble

Douglas, Bob,

You were both on the money about my creating the problem myself. I was
overlooking that I had set my variable "BnsAmnt" as an Integer instead of
Double. I feel like such an idiot after all the time I spent on this. Thanks
so much for all your help. I guess I couldn't see the forest for the trees.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top