Strange Rounding

V

Vel

Hello

I have a report in which I use a couple of public variables (PageSum and PagePaid) to calculate an amount charged and paid per page. They work fine. The formatting of the form I'm printing my report on requires me to separate the dollars from the cents in the charges, payments, and balance

to get these values I use the following formul
txtChargeD: =Int(PageSum
txtChangeD: =(PageSum-Int(PageSum))*10
txtPaidD: =Int(PagePaid
txtPaidC: =(PagePaid-Int(PagePaid))*10

txtBalanceD: =Int(PageSum-PagePaid
txtBalanceC: =((PageSum-PagePaid)-Int(PageSum-PagePaid))*10

The problem is that the balance is rounding to the nearest ten cents. I've tried various workarounds, but it always comes out the same. For example
PageSum=65.0
PagePaid=29.1
all fields calculate correctly, except for txtBalanceC, which comes out to 90 when it should be 87. I even tried using two separate textboxes, txtIntDiff and txtDiff, which were the two respective portions of txtBalanceC. The ouptut on the report displayed the values 2587 and 2500, yet when I subtracted the two I still ended up with 90. I assume this has something to do with underlying stored values, but I can't figure out a better way to do this. Is there something simple I'm missing (such as a way to separate the dollars from the cents)?

Thank
Vel
 
R

RobFMS

--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Vel said:
Hello,

I have a report in which I use a couple of public variables (PageSum and
PagePaid) to calculate an amount charged and paid per page. They work fine.
The formatting of the form I'm printing my report on requires me to separate
the dollars from the cents in the charges, payments, and balance.
to get these values I use the following formula
txtChargeD: =Int(PageSum)
txtChangeD: =(PageSum-Int(PageSum))*100
txtPaidD: =Int(PagePaid)
txtPaidC: =(PagePaid-Int(PagePaid))*100

txtBalanceD: =Int(PageSum-PagePaid)
txtBalanceC: =((PageSum-PagePaid)-Int(PageSum-PagePaid))*100

The problem is that the balance is rounding to the nearest ten cents.
I've tried various workarounds, but it always comes out the same. For
example:
PageSum=65.00
PagePaid=29.13
all fields calculate correctly, except for txtBalanceC, which comes out to
90 when it should be 87. I even tried using two separate textboxes,
txtIntDiff and txtDiff, which were the two respective portions of
txtBalanceC. The ouptut on the report displayed the values 2587 and 2500,
yet when I subtracted the two I still ended up with 90. I assume this has
something to do with underlying stored values, but I can't figure out a
better way to do this. Is there something simple I'm missing (such as a way
to separate the dollars from the cents)?
 
R

RobFMS

Vel

This article should provide you some value.

When Access Math Doesn't Add Up
http://www.fmsinc.com/tpapers/math/index.html

--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Vel said:
Hello,

I have a report in which I use a couple of public variables (PageSum and
PagePaid) to calculate an amount charged and paid per page. They work fine.
The formatting of the form I'm printing my report on requires me to separate
the dollars from the cents in the charges, payments, and balance.
to get these values I use the following formula
txtChargeD: =Int(PageSum)
txtChangeD: =(PageSum-Int(PageSum))*100
txtPaidD: =Int(PagePaid)
txtPaidC: =(PagePaid-Int(PagePaid))*100

txtBalanceD: =Int(PageSum-PagePaid)
txtBalanceC: =((PageSum-PagePaid)-Int(PageSum-PagePaid))*100

The problem is that the balance is rounding to the nearest ten cents.
I've tried various workarounds, but it always comes out the same. For
example:
PageSum=65.00
PagePaid=29.13
all fields calculate correctly, except for txtBalanceC, which comes out to
90 when it should be 87. I even tried using two separate textboxes,
txtIntDiff and txtDiff, which were the two respective portions of
txtBalanceC. The ouptut on the report displayed the values 2587 and 2500,
yet when I subtracted the two I still ended up with 90. I assume this has
something to do with underlying stored values, but I can't figure out a
better way to do this. Is there something simple I'm missing (such as a way
to separate the dollars from the cents)?
 
Top