请教这个计算器中的百分号与分数计算的代码
程序代码:
关键部分代码: public partial class frmStandCalculator : Form { public float number1 = 0;//存储前一个操作数; public bool flag = false;//标记单击了操作符没有,false为还未击操作符,ture为单击了操作符 public char doflag = '+';//初始化操作符,单击了操作符时存储操作符号 public bool pointflag = false;//标志是否单击了小数点;false为未击,true为已经单击; public float number2 = 0;//存储单击=号时TextNum的值 public int n = 0;//记录是击了=键还是未击。 public float M = 0; public string COPYM = ""; .......................................... .......................................... .......................................... //开平方根: private void btnSqrt_Click(object sender, EventArgs e) { if (TxtNum.Text.Trim() != "") { float tempnumber = (float)Math.Sqrt(float.Parse(TxtNum.Text));//Math.Sqrt()结 //果为double型,所以要用float强制转换 TxtNum.Text = tempnumber.ToString(); } flag = true; } //百分号: private void btnPercent_Click(object sender, EventArgs e) { } //分数: private void btnFraction_Click(object sender, EventArgs e) { } }
程序代码:
//参考:Site:<span style="color: #008000; text-decoration: underline;">http://apps.hi.baidu.com/share/detail/1192593[/color][/color] private void Button_Percent_Click(object sender, EventArgs e) { number = Convert.ToString(Convert.ToDouble(TextBox.Text) / 100); TextBox.Text = number; number = ""; } private void Button_Reciprocal_Click(object sender, EventArgs e) { if (Convert.ToDouble(TextBox.Text) ==0) { this.TextBox.Text = "error"; } else { number2 = Convert.ToDouble(TextBox.Text); number = ""; TextBox.Text = Convert.ToString(1 / number2); } }
[ 本帖最后由 shared2012 于 2012-6-7 23:21 编辑 ]