Solved

Subtraction using double

Posted on 2004-04-29
4
204 Views
Last Modified: 2010-05-02
Hi,

Im am running the following code:
frmAddToFile.txtBalance = Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - Val(frmAddToFile.txtTotalPaidToDate) - Val(txtAmountPaying.Text)

where frmAddToFile.adoFileInformation.Recordset.Fields("saleamount") = 10707.49
and frmAddToFile.txtTotalPaidToDate = 8022.89
and txtAmountPaying.Text = 2684.60

this should compute to 0 but instead it = -4.54747350.......

I understand this has to do with the way it is stored in binary, but I need a way of making this work.

Thanks!
0
Comment
Question by:FTIISD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 100 total points
ID: 10952137
frmAddToFile.txtBalance = (Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - (Val(frmAddToFile.txtTotalPaidToDate) + Val(txtAmountPaying.Text))

S
0
 
LVL 6

Assisted Solution

by:prasitlee
prasitlee earned 100 total points
ID: 10952161
HI FTIISD,
    Did you try to use the function cdbl() insteadof val() or not ? I think it might be better ...
                                                                   Meng
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 10952178
Try:

frmAddToFile.txtBalance = Val(Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - Val(frmAddToFile.txtTotalPaidToDate)) - Val(txtAmountPaying.Text)

or is will be better if you use CCur function instead:

frmAddToFile.txtBalance = CCur(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - CCur(frmAddToFile.txtTotalPaidToDate) - CCur(txtAmountPaying.Text)
0
 

Author Comment

by:FTIISD
ID: 10952274
Was able to get it working with CCur()

Thanks for the help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question