Solved

Subtraction using double

Posted on 2004-04-29
4
203 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 51

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

756 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