I need to get the sum of two numbers but i do not know how

example

**what the result should be:**
            1,000,000 + 2,000 = 1,002,000

**my code's result:**
            1,000,000 + 2,000 = 3
                     It seems that my code only adds the numbers before comma (,)

My code do not compute it properly. this is my code any way

    lblTotal.Text = Format(Val(lblTotal.Text), "#,##0.00")
    lblVatable.Text = Format(Val(lblVatable.Text), "#,##0.00")
    lblTax.Text = Format(Val(lblTax.Text), "#,##0.00")

Use the Replace function to replace the commas with nulls before you do the conversion to int and the addition.

Since your converting the string to Double in order to format it, you could store that Double, and use that in your calculations.

Dim intTotal As Double = Val(lblTotal.Text)
lblTotal.Text = intTotal.ToString("#,###,##0.00")

Dim intVatable As Double = Val(lblVatable.Text)
lblVatable.Text = intVatable.ToString("#,###,##0.00")

Dim intTax As Double = Val(lblTax.Text)
lblTax.Text = intTax.ToString("#,###,##0.00")

If you will manually enter the numbers with the commas you can just simple create the variables that will store the numbers before the commas and also create the variable that will store the commas since it not easy or possible to calculate the numbers with the string format so here is an idea of how you can go about doing it.

Dim TotalNoBforCommaOne As Double
Dim TotalNoBforCommaTwo As Double
Dim TotalNoBforCommaThree As Double
Dim VatableNoBforCommaOne As Double
Dim VatableNoBforCommaTwo As Double
Dim VatableNoBforCommaThree As Double
Dim TaxNoBforCommaOne As Double
Dim TaxNoBforCommaTwo As Double
Dim TaxNoBforCommaThree As Double

' Now you need to track the textbox to detect if the comma has been preesed then
' if the comma is pressed then if it the first time in that textbox then you can
' Assign the desired variable with the current numbers on the textbox then clear the
' textbox so that you can track other entries and assign then with the correct variable.

hmmm how about this??..

Dim n1 as Double = 1000000
Dim n2 as Double = 2000
Dim nTot as Double = n1 + n2

lblTotal.Text = nTot.ToString("#,#", CultureInfo.InvariantCulture)

try dis one.

    Dim total as integer
    dim firstnumber as integer
    dim secondnumber as integer

    total = Format(csng(firstnumber) + Csng(secondnumber),"#,###,##0.00")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.