将2个文本框值相乘并显示在c#的第3个文本框中 [英] Multiply 2 textbox values and display in 3rd textbox in c#

查看:240
本文介绍了将2个文本框值相乘并显示在c#的第3个文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想要多个两位十进制数并在第三个文本框中显示结果或者标签。文字

通知:我的两个十进制数是我的数据库sql server的两个字段的数据,但是我的代码没有工作请帮帮我。和字段类型是十进制的

我的代码:



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 :

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?

推荐答案

rezaeti写道:
rezaeti wrote:

需要改变字段类型或更改我的代码?

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





是的,你真的需要更改你的代码!



取决于本地化(国家,地区设置)十进制和/或千位分隔符可能不同。因此,您必须使用 Decimal.TryParse(String,NumberStyles,IFormatProvider,十进制) [ ^ ]方法,使用特定的 CultureInfo类 [ ^ ]。



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[^].


这篇关于将2个文本框值相乘并显示在c#的第3个文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆