Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to multiple two decimal number and display result in 3rd textbox or label.text
notice: my two decimal number are data of two field of my database sql server but my code does not work please help me. and type of field is decimal
my code :

C#
protected void Button1_Click1(object sender, EventArgs e)
    {

        Decimal a, b;

        bool isAValid = Decimal.TryParse(TextBox1.Text, out a);
        bool isBValid = Decimal.TryParse(TextBox2.Text, out b);
        if (isAValid && isBValid)
                Label2.Text = (a * b).ToString();

            else
            Label2.Text = "Invalid input";
        }

    }


Is Necessary to chang type of field or change my code?
Posted
Updated 6-Oct-15 10:35am
v2
Comments
Afzaal Ahmad Zeeshan 6-Oct-15 16:36pm    
Why it doesn't work?
rezaeti 6-Oct-15 16:50pm    
thanks it work
rezaeti 6-Oct-15 16:50pm    
thanks it work
If you could add one answer with the details of problem and how you solved, that would be awesome.

1 solution

rezaeti wrote:
Is Necessary to chang type of field or change my code?


Yes, you do really have to change your code!

Depending on localization (country, regional settings) the decimal and/or thousand separator may differ. So, you have to use Decimal.TryParse(String, NumberStyles, IFormatProvider, Decimal)[^] method, which provides proper "convertion" using specific CultureInfo class[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900