C# 在文本框中以十进制格式输入

C# 在文本框中以十进制格式输入,c#,C#,下面的代码,我现在使用的不给我所需要的 textBox1.Text = textBox1.Text + enteredvalue; 我想实现在文本框中输入十进制值而不必输入“” 如果输入3,文本框中的输出应为00.03,然后如果输入5,则输出应为00.35,依此类推 我如何做到这一点 编辑:我是通过创建一个方法并在每次按下输入号码时调用它来实现的 public void dropcashvalue(string inputdigit) { if (txtDropC

下面的代码,我现在使用的不给我所需要的

textBox1.Text = textBox1.Text + enteredvalue;
我想实现在文本框中输入十进制值而不必输入“

如果输入3,文本框中的输出应为
00.03
,然后如果输入
5
,则输出应为
00.35
,依此类推

我如何做到这一点

编辑:我是通过创建一个方法并在每次按下输入号码时调用它来实现的

   public void dropcashvalue(string inputdigit)
    {
        if (txtDropCash.Text == "00.00")
        {
            txtDropCash.Text = "";
            this.dropstring = "";
        }
        this.dropstring = this.dropstring + inputdigit;
        txtDropCash.Text = (Convert.ToDouble(this.dropstring) / 100).ToString("F2");
    }
我的文本框和inputnumber设计如下所示


您需要为计算值维护一个附加变量

double enteredValue = 0.0;
无论何时输入新数字,您都将其添加到您的价值中:

textBox.Text = (enteredValue/100).ToString("F2");
enteredValue=enterValue*10+输入位数

在文本框中,显示值的格式化版本:

textBox.Text = (enteredValue/100).ToString("F2");

谢谢@DrKoch。您的代码让位于我的要求。public void dropcashvalue(string inputdigit){if(txtdopcash.Text==“00.00”){txtdopcash.Text=”“;this.dropstring=“”;}this.dropstring=this.dropstring+inputdigit;txtdopcash.Text=(Convert.ToDouble(this.dropstring)/100)。ToString(“F2”);}我使用了上面的方法,每次按下一个数字都会调用它。像dropcashvalue(“1”);它可以工作。Dok会将它添加到@DrKoch