我要在编辑框里填入大于0小于1的实数时,显示的效果为0.0001.就是保留有效数值为4位,如果填入的是大于1的整数时就保留两位有效值。不知道大家有没有遇到过这样的问题?在线等!
解决方案 »
- C#导出Excel代码
- 求助!SQL连接的问题
- 如何获取当前webbrowser控件中所浏览网页的cookies呢?
- WinForm中DataGridViewCheckBoxColumn的用法问题!
- 图片问题,谢谢各位高手
- 未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中。搞了好久总是出现这个问题,郁闷,在线等待中....
- 倾家荡产求解……画列表的问题
- ……找不到入口点,怎么办?
- MVVM中两个View使用同一个ViewModel怎样区分是谁调用了它
- 大家看看这样条件的.Net项目经理大概需要多少薪水?
- vs2005 创建 C/S项目的问题
- C# 2003 winform 导出excel报表问题
if(s>0||s<1){s.ToString("#0.0000");}if(s>1){s.ToString("#0.00");}
if(s>0||s <1){s.ToString("#0.0000");}if(s>1){s.ToString("#0.00");}
if(s>0&&s <1){s.ToString("#0.0000");}if(s>1){s.ToString("#0.00");}
主要是格式化数字。
object.ToString()里面参数有很多个
而且很有用,
详细去baidu吧
private void textBox1_TextChanged(object sender, EventArgs e)
{
Decimal s = Convert.ToDecimal(textBox1.Text.ToString().Trim());
if (s > 0 && s < 1)
{
s.ToString("#0.0000");
}
if (s > 1)
{
s.ToString("#0.00");
}
textBox2.Text = Convert.ToString(s);
}
{
Decimal s = Convert.ToDecimal(textBox1.Text.ToString().Trim());
if (s > 0 && s < 1)
{
s = s.ToString("#0.0000"); }
if (s > 1)
{
s= s.ToString("#0.00"); }
textBox2.Text = Convert.ToString(s);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string temp;
Decimal s = Convert.ToDecimal(textBox1.Text.ToString().Trim());
if (s > 0 && s < 1)
{
temp = s.ToString("#0.0000"); }
if (s > 1)
{
temp= s.ToString("#0.00"); }
textBox2.Text = Convert.ToString(temp);
}
复杂了.... string temp = null;
Decimal s = Convert.ToDecimal(textBox1.Text.ToString().Trim());
if (s > 0 && s < 1)
{
temp = s.ToString("#0.0000");
}
if (s > 1)
{
temp = s.ToString("#0.00");
}
textBox2.Text = temp;
{
if (textBox1.Text=="")
{
textBox2.Text = textBox1.Text;
}
else
{
try
{
Single s = Convert.ToSingle(textBox1.Text);
if (s > 0 && s < 1)
{ textBox2.Text = string.Format("{0:0.0000}", s);
}
if (s >= 1)
{ textBox2.Text = string.Format("{0:f}", s);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message); }
finally
{
}
}
}
if ((0 < de) && (1 > de))
{
this.textBox1.Text = de.ToString("#0.0000"); }
else if (1 < de)
{
this.textBox1.Text = de.ToString("#0.00");
}