using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace currency
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.textBox2.ReadOnly = true;
this.button2.Enabled = false;
this.TopMost = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "美元";
}
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "英镑";
} } private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "日元";
}
} private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length == 0)
{
MessageBox.Show("wrong");
}
else
{
string str = this.textBox1.Text;
string r = @"[1-9]\d+";
str = System.Text.RegularExpressions.Regex.Match(str, r).ToString(); //RegularExpressions to match the number
if (radioButton1.Checked)
{
double num = (double.Parse(str)) / 8.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
}
if (radioButton2.Checked)
{
double num = (double.Parse(str)) / 10.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
}
if (radioButton3.Checked)
{
double num = (double.Parse(str)) * 10.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
} }
} private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
this.label2.Text = "美元";
} private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar !=0 ) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
}
}为什么我输入带有小字点的数字后,小数点后面的数却不能参与运算?
比如我输入45.5,乘以10以后就本该是455,但是却输入450
原因?????????????????
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace currency
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.textBox2.ReadOnly = true;
this.button2.Enabled = false;
this.TopMost = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "美元";
}
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "英镑";
} } private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
this.button2.Enabled = true;
this.label2.Text = "日元";
}
} private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length == 0)
{
MessageBox.Show("wrong");
}
else
{
string str = this.textBox1.Text;
string r = @"[1-9]\d+";
str = System.Text.RegularExpressions.Regex.Match(str, r).ToString(); //RegularExpressions to match the number
if (radioButton1.Checked)
{
double num = (double.Parse(str)) / 8.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
}
if (radioButton2.Checked)
{
double num = (double.Parse(str)) / 10.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
}
if (radioButton3.Checked)
{
double num = (double.Parse(str)) * 10.0;
string str1 = num.ToString();
this.textBox2.Text = str1;
} }
} private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
this.label2.Text = "美元";
} private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar !=0 ) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
}
}为什么我输入带有小字点的数字后,小数点后面的数却不能参与运算?
比如我输入45.5,乘以10以后就本该是455,但是却输入450
原因?????????????????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货