C#ASP.NET中的10位计算器问题 [英] 10 digits calculator problems in C# ASP.NET
本文介绍了C#ASP.NET中的10位计算器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被要求按0按钮并保持为0而不是保持增加000000。我应该在这段代码中添加什么?
I'm asked to press "0" button and it remains 0 instead of keeping increase "000000". What should I add in this code?
<pre>#region EQUAL CALCULATION
protected void Equal_Click(object sender, EventArgs e)
{
decimal output;
//Check whether it has data or not
try
{
Expression a = new Expression(lblExpression.Text);
if (decimal.TryParse(a.Evaluate().ToString(), out output))
{
lblResult.Text = output.ToString();
lblExpression.Text = "";
}
}
catch (Exception)
{
lblExpression.Text = lblExpression.Text;
lblResult.Text = "Invalid Calculation";
}
}
#endregion
#region BUTTON FUNCTION
protected void Btn1_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button1.Text;
}
protected void Btn2_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button2.Text;
}
protected void Btn3_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button3.Text;
}
protected void Btn4_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button4.Text;
}
protected void Btn5_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button5.Text;
}
protected void Btn6_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button6.Text;
}
protected void Btn7_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button7.Text;
}
protected void Btn8_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button8.Text;
}
protected void Btn9_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button9.Text;
}
protected void Btn0_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + button0.Text;
}
#endregion
#region OPERATOR
protected void Decimal_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + Decimal.Text;
}
protected void Plus_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + Plus.Text;
}
protected void Minus_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + Minus.Text;
}
protected void Divide_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + Divide.Text;
}
protected void Multiply_Click(object sender, EventArgs e)
{
lblExpression.Text = lblExpression.Text + Multiply.Text;
}
#endregion
protected void Reset_Click(object sender, EventArgs e)
{
lblExpression.Text = "";
lblResult.Text = "0";
}
protected void Back_Click(object sender, EventArgs e)
{
//remove by 1 integer
string s = "";
if (lblExpression.Text.Length > 1)
{
s = lblExpression.Text;
s = s.Substring(0, s.Length- 1);
}
lblExpression.Text = s;
}
我的尝试:
我不知道我应该在哪里添加
What I have tried:
I don't know where should i add
推荐答案
使用Microsoft.VisualBasic
你可以使用VAL()函数来避免上述问题。
using Microsoft.VisualBasic
you can use VAL() function to avoid above problem.
这篇关于C#ASP.NET中的10位计算器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文