Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Subtraction?

Status
Not open for further replies.

cabobound

Programmer
Jul 11, 2007
80
0
0
US
I am trying to subtract 1 number from another. The first number is passed in a parameter and the other is the sum of a running total. When I display the numbers I get a them, even when displayed as cDbl(x) and cDbl(y). The problem is when I subtract x from y I get 9.99999999999091E-03 even when the difference is 0.01! I cannot get this corrected. Does anyone have an idea?

x=1526.6
y=1526.59
z=9.99999999999091E-03

Any help is greatly appreciated! Thanks in advance!

K
 
That is likely a result of floating point calculations. I would suggest you use the Round function.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Ok, I rounded both numbers to 0.XX. There was not a change. I need to have this carried out 2 decimal places.
 
it should work if you try rounding as gmmastros suggested:
x=cdbl(1526.6)
y=cdbl(1526.59)
z=round(cdbl(x-y),2)
i got .01
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top