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)
BUY
  • 705
  • 1
  • 11
  • 30
B.Nishan
  • 19
  • 2
  • 5
  • 2
    What is the exact content of the two textboxes that you are trying to convert in a number? – Steve Jun 04 '18 at 07: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. – B.Nishan Jun 04 '18 at 08:22
  • You need to convert the content of the textbox you should try: `CDbl(Val(txtPayment.Text))` try looking at this: https://stackoverflow.com/questions/1172306/convert-string-to-double-vb – Mederic Jun 04 '18 at 08: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)` – Fabio Jun 04 '18 at 08: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)` – AJD Jun 04 '18 at 19:47
  • How is $5000 being written? My guess is that its as `5,000` and `,` is being treated as a decimal separator so it is parsing it as just 5. Please include the exact values of `txtTotalAmount.Text` and `txtPayment.Text`. – Chris Jun 11 '18 at 15:45

1 Answers1

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?

JosephC
  • 917
  • 4
  • 12