0

I have created a small currency calculation program in vb.net. But when I am calculating two currency values, it is showing the wrong amount. My text boxes are already in currency format. Kindly looking for your help please.

Here is my code for calculation:

txtBalance.Text = Val(txtPayment.Text) + Val(txtTotalAmount.Text)
6
  • 2
    What is the exact content of the two textboxes that you are trying to convert in a number? Commented Jun 4, 2018 at 7:56
  • If I calculate two currency value, $650.00 and $5000.00 it should get output $5650.00 but I'm getting output 655 which is totally wrong calculation. Commented Jun 4, 2018 at 8:22
  • You need to convert the content of the textbox you should try: CDbl(Val(txtPayment.Text)) try looking at this: stackoverflow.com/questions/1172306/convert-string-to-double-vb Commented Jun 4, 2018 at 8:25
  • Do not use Visual Basic methods. You are writing code in vb.net. You need convert text to decimal type. Dim payment = Decimal.Parse(txtPayment.Text) Commented Jun 4, 2018 at 8:55
  • String = (Assumed number from string) + (Assumed number from string) - adding apples and wanting oranges! Should be Number = (parsed number from string) + (parsed number from string) Commented Jun 4, 2018 at 19:47

1 Answer 1

0
TextBox3.Text = Convert.ToDouble(TextBox1.Text) + Convert.ToDouble(TextBox2.Text)

Also

How do I convert from a string to an integer in Visual Basic?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.