Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I stop rounding of my calculation results.

4 views
Skip to first unread message

Weeble

unread,
Nov 25, 2009, 12:49:03 PM11/25/09
to
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.

KARL DEWEY

unread,
Nov 25, 2009, 1:08:02 PM11/25/09
to
Calculation are done OUTSIDE of the table so changing the table won't do it.
You need to apply the formating to the object that is displaying the
calculation.

--
Build a little, test a little.

Douglas J. Steele

unread,
Nov 25, 2009, 1:35:57 PM11/25/09
to
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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Weeble" <Wee...@discussions.microsoft.com> wrote in message
news:435A0166-C727-44B0...@microsoft.com...

Weeble

unread,
Nov 25, 2009, 2:55:02 PM11/25/09
to
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?

"Douglas J. Steele" wrote:

> .
>

Douglas J. Steele

unread,
Nov 25, 2009, 3:10:08 PM11/25/09
to
How are you doing the calculation? It's possible that it's being coerced
into an integer.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Weeble" <Wee...@discussions.microsoft.com> wrote in message

news:8B3AB476-17A0-44EF...@microsoft.com...

Weeble

unread,
Nov 30, 2009, 12:40:03 PM11/30/09
to
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.

"Douglas J. Steele" wrote:

> .
>

Douglas J. Steele

unread,
Nov 30, 2009, 2:17:45 PM11/30/09
to
You show a calculation, but not how that calculation is assigned to the
control. How are you doing that?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Weeble" <Wee...@discussions.microsoft.com> wrote in message

news:FD4F3F43-5BBF-4B76...@microsoft.com...

Bob Quintal

unread,
Nov 30, 2009, 7:06:32 PM11/30/09
to
=?Utf-8?B?V2VlYmxl?= <Wee...@discussions.microsoft.com> wrote in
news:FD4F3F43-5BBF-4B76...@microsoft.com:

> 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


--
Bob Quintal

PA is y I've altered my email address.

Weeble

unread,
Dec 1, 2009, 10:30:01 AM12/1/09
to
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.

"Douglas J. Steele" wrote:

> .
>

0 new messages