473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rounding Dollar Amounts

Hello Everyone,

I'm using the following on a form in my database:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100
In this case, I want to calculate a total for an order. If the
LineTaxExempt field is checked (meaning tax exempt), the total is
figured by the ([Qty] field X [Price] field)+the [ShippingHandlin g]
field.

If the LineTaxExempt is not checked, then the above total, including
shipping, is multiplied by 6% sales tax or 1.06. I then want this
value rounded up to 2 decimal places. This control is a running total
of the order.

This works most of the time, but I have run into a few rounding errors.

For example:

With exempt checked

1(Qty)X27.90(Pr ice) + 6.44(ShippingHa ndling) gives me $34.35
instead of $34.34

With tax exempt checked (and multiple lines)

2(Qty)X141.02(P rice) + 0.00(ShippingHa ndling)
10(Qty)X4.12(Pr ice) + 0.00(ShippingHa ndling) gives me a
grand total of $323.25 instead of $323.24

It's frustrating because it seems like it works part of the time and
rounds wrong the other part of the time. By "rounds wrong", I mean I
set it wrong to round. Any help would be greatly appreciated on how to
modify this to give me the correct result.

Thanks,

-Chad

Nov 7 '06 #1
6 2250
Have you checked your field datatypes? Set [Qty] to Integer if possible and
[Price] and [ShippingHandlin g] to Currency (2 places). I generally avoid
using Single because of rounding issues; use Double instead. HTH

sh************* **********@yaho o.com wrote:
>Hello Everyone,

I'm using the following on a form in my database:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100

In this case, I want to calculate a total for an order. If the
LineTaxExemp t field is checked (meaning tax exempt), the total is
figured by the ([Qty] field X [Price] field)+the [ShippingHandlin g]
field.

If the LineTaxExempt is not checked, then the above total, including
shipping, is multiplied by 6% sales tax or 1.06. I then want this
value rounded up to 2 decimal places. This control is a running total
of the order.

This works most of the time, but I have run into a few rounding errors.

For example:

With exempt checked

1(Qty)X27.90(P rice) + 6.44(ShippingHa ndling) gives me $34.35
instead of $34.34

With tax exempt checked (and multiple lines)

2(Qty)X141.02( Price) + 0.00(ShippingHa ndling)
10(Qty)X4.12(P rice) + 0.00(ShippingHa ndling) gives me a
grand total of $323.25 instead of $323.24

It's frustrating because it seems like it works part of the time and
rounds wrong the other part of the time. By "rounds wrong", I mean I
set it wrong to round. Any help would be greatly appreciated on how to
modify this to give me the correct result.

Thanks,

-Chad
--
Message posted via http://www.accessmonster.com

Nov 7 '06 #2
sh************* **********@yaho o.com wrote:
Hello Everyone,

I'm using the following on a form in my database:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100
In this case, I want to calculate a total for an order. If the
LineTaxExempt field is checked (meaning tax exempt), the total is
figured by the ([Qty] field X [Price] field)+the [ShippingHandlin g]
field.

If the LineTaxExempt is not checked, then the above total, including
shipping, is multiplied by 6% sales tax or 1.06. I then want this
value rounded up to 2 decimal places. This control is a running total
of the order.

This works most of the time, but I have run into a few rounding errors.

For example:

With exempt checked

1(Qty)X27.90(Pr ice) + 6.44(ShippingHa ndling) gives me $34.35
instead of $34.34

With tax exempt checked (and multiple lines)

2(Qty)X141.02(P rice) + 0.00(ShippingHa ndling)
10(Qty)X4.12(Pr ice) + 0.00(ShippingHa ndling) gives me a
grand total of $323.25 instead of $323.24

It's frustrating because it seems like it works part of the time and
rounds wrong the other part of the time. By "rounds wrong", I mean I
set it wrong to round. Any help would be greatly appreciated on how to
modify this to give me the correct result.

Thanks,

-Chad
Here's a shot in the dark.

Instead of:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100

try sliding a right parenthesis to the left:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g]))*1.06))*100)) )/100

James A. Fortune
CD********@Fort uneJames.com

Nov 7 '06 #3
CD********@Fort uneJames.com wrote:
sh************* **********@yaho o.com wrote:
Hello Everyone,

I'm using the following on a form in my database:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100
In this case, I want to calculate a total for an order. If the
LineTaxExempt field is checked (meaning tax exempt), the total is
figured by the ([Qty] field X [Price] field)+the [ShippingHandlin g]
field.

If the LineTaxExempt is not checked, then the above total, including
shipping, is multiplied by 6% sales tax or 1.06. I then want this value rounded up to 2 decimal places. This control is a running total of the order.

This works most of the time, but I have run into a few rounding errors.

For example:

With exempt checked

1(Qty)X27.90(Pr ice) + 6.44(ShippingHa ndling) gives me $34.35
instead of $34.34

With tax exempt checked (and multiple lines)

2(Qty)X141.02(P rice) + 0.00(ShippingHa ndling)
10(Qty)X4.12(Pr ice) + 0.00(ShippingHa ndling) gives me a
grand total of $323.25 instead of $323.24

It's frustrating because it seems like it works part of the time and
rounds wrong the other part of the time. By "rounds wrong", I mean I
set it wrong to round. Any help would be greatly appreciated on how to
modify this to give me the correct result.

Thanks,

-Chad

Here's a shot in the dark.

Instead of:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100

try sliding a right parenthesis to the left:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g]))*1.06))*100)) )/100

James A. Fortune
CD********@Fort uneJames.com


Thanks to everyone for the help. This is the info for my 3 fields:

QTY
-------
Field: Double
Format: Standard
Decimal Places: 2

Price
----------
Format: Currency
Decimal Places: 4

ShippingHandlin g
-------------------------------
Format: Currency
Decimal Places: 2

I tried setting QTY to Integer/Auto-Decimal, Price and Shipping
handling to Currency/2 decimal places. I still had rounding errors
some of the time. I really need 4 decimal places on price since some
unit prices require 4.

I also tried moving the parenthesis, and still had rounding errors part
of the time.

Is there a better way to round up to 2 decimal places other than the
=-Int(-Sum([Fieldname]) * 100) / 100 method that will be right?

Thanks,

-Chad

Nov 8 '06 #4
Hi Chad,

I think you have to look at your rounding procedure. Int of a negative
number returns the next lower integer: -Int(-9.2) wil give 10
So, -Int(-9.2) + (-Int(-9.2)) = 20, instead of 18 as expected.

A better way to round (i.e. 9.2 gives 9 and 9.7 gives 10) is:
rounded_value = Int(original_va lue + 0.5).

Or, when you work dollars (or euro's):
rounded_value = Int(100 * original_value + 0.5)/100. Remember in this
case that multiplication is done before addition!

Your running total should be based on these rounded values.

Regards, HBinc.

sh************* **********@yaho o.com schreef:
Hello Everyone,

I'm using the following on a form in my database:

=(-Int(-Sum((IIf([LineTaxExempt]=Yes,(([Qty]*[Price])+([ShippingHandlin g])),
((([Qty]*[Price])+[ShippingHandlin g])*1.06))*100))) )/100
In this case, I want to calculate a total for an order. If the
LineTaxExempt field is checked (meaning tax exempt), the total is
figured by the ([Qty] field X [Price] field)+the [ShippingHandlin g]
field.

If the LineTaxExempt is not checked, then the above total, including
shipping, is multiplied by 6% sales tax or 1.06. I then want this
value rounded up to 2 decimal places. This control is a running total
of the order.

This works most of the time, but I have run into a few rounding errors.

For example:

With exempt checked

1(Qty)X27.90(Pr ice) + 6.44(ShippingHa ndling) gives me $34.35
instead of $34.34

With tax exempt checked (and multiple lines)

2(Qty)X141.02(P rice) + 0.00(ShippingHa ndling)
10(Qty)X4.12(Pr ice) + 0.00(ShippingHa ndling) gives me a
grand total of $323.25 instead of $323.24

It's frustrating because it seems like it works part of the time and
rounds wrong the other part of the time. By "rounds wrong", I mean I
set it wrong to round. Any help would be greatly appreciated on how to
modify this to give me the correct result.

Thanks,

-Chad
Nov 8 '06 #5
sh************* **********@yaho o.com wrote:
Thanks to everyone for the help. This is the info for my 3 fields:

QTY
-------
Field: Double
Format: Standard
Decimal Places: 2

Price
----------
Format: Currency
Decimal Places: 4

ShippingHandlin g
-------------------------------
Format: Currency
Decimal Places: 2

I tried setting QTY to Integer/Auto-Decimal, Price and Shipping
handling to Currency/2 decimal places. I still had rounding errors
some of the time. I really need 4 decimal places on price since some
unit prices require 4.

I also tried moving the parenthesis, and still had rounding errors part
of the time.

Is there a better way to round up to 2 decimal places other than the
=-Int(-Sum([Fieldname]) * 100) / 100 method that will be right?
I don't use the Currency type in calculations much. Here's another to
try:

'Begin Module Code
Public Function RoundUpCents(x As Double) As Currency
x = x * 100
RoundUpCents = CCur((Int(x) + Abs(x <Int(x))) / 100#)
End Function
'End Module Code

James A. Fortune
CD********@Fort uneJames.com

Nov 8 '06 #6
I suggest you use double for all of your numeric field types. Do you think
that it will require too much overhead? Whenever I've ever mixed numeric
data types in calculations, I've found rounding errors. You can write your
own rounding function, but I think you agree that this would be an "ugly"
solution.

sh************* **********@yaho o.com wrote:
Hello Everyone,
[quoted text clipped - 49 lines]
>James A. Fortune
CD********@Fort uneJames.com

Thanks to everyone for the help. This is the info for my 3 fields:

QTY
-------
Field: Double
Format: Standard
Decimal Places: 2

Price
----------
Format: Currency
Decimal Places: 4

ShippingHandli ng
-------------------------------
Format: Currency
Decimal Places: 2

I tried setting QTY to Integer/Auto-Decimal, Price and Shipping
handling to Currency/2 decimal places. I still had rounding errors
some of the time. I really need 4 decimal places on price since some
unit prices require 4.

I also tried moving the parenthesis, and still had rounding errors part
of the time.

Is there a better way to round up to 2 decimal places other than the
=-Int(-Sum([Fieldname]) * 100) / 100 method that will be right?

Thanks,

-Chad
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200611/1

Nov 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
15476
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
5
2501
by: astro | last post by:
I have a report/invoice that lists volume, price per unit, and extended price. My problem is being able to get the extended price by multiplying the x . With just 2 decimal places on both volume and I've discovered there is not way to get the exact on invoices with extended price values greater then 50k due to rounding errors. This customer wants only 2 decimal places on the invoice. Is there an industry standard for this? The ...
1
4666
by: W. Adam | last post by:
How do round up to nearest dollar in VB.Net.(to the next dollar price). If i get 9.46 or 9.65, i need to round up to 10.00 Thanks in Advance
9
5820
by: bdog4 | last post by:
I want to validate a number to so that they can only input $2.00, 5.00, 7.00, 50.00 etc... I don't wan them to be able to put cents on the amount. It can either either be 2 or 2.00 Any ideas on how I can do this? Thanks
3
2264
by: mark.a.lemoine | last post by:
I need to be selecting records based on the value of a string-format currency value. Specifically, I have a table with a field of type varchar(50). Stored in this field is a dollar-formatted value, complete with the dollar sign and commas for the thousands separator (and an optional leading minus sign for negative values). For instance: $1,234.56. One restriction I have to live with is that I can't change the schema of the table or...
11
6656
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 seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
1
5126
by: gbstclair | last post by:
I new to c programming and was wondering if someone can please help me to understand how to get the following printf statements to align up the dollar amounts when displayed? printf ("\n\n*** Bank Record ***\n\n"); printf ("\n Starting Balance: $ %2.2f \n\n", initial_balance); for (x = 0; x < number_of_deposits; x++) { printf ("\n Deposit #%i: %2.2f \n\n", x + 1, deposits); }
248
1510
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) It then updates the value with numberOfPrecisions after the decimal
2
5121
by: clintonb | last post by:
Victor said: The double value that I'm trying to convert to GCSMoney (which is implemented as cents) was produced by multiplying a dollar amount by an interest rate to get interest. double amount = 126.60; double interestRate = .075; double interest = amount * interestRate;
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.