日期:2014-05-19  浏览次数:20876 次

急!!!!!如何去掉小数点后面的0???
如:
decimal   dec   =   2.50000
如何去掉后面多作的0,显示2.5呢?
有什么方法?

------解决方案--------------------
decimal dec = 2.50000m;
string s = dec.ToString( "0.0 ");
------解决方案--------------------
更正一下

decimal dec = 2.50000m;
string temp = dec.ToString();
while(true)
{
if(temp[temp.length-1]== '0 ')
temp=temp.RemoveAt(temp.length);
else
break;
}

float num=float.Parse(temp); //num=2.5

------解决方案--------------------
string values=this.textBox1.Text.ToString().Trim();
string tempR= " ",tempL= " ";
try
{
tempL=values.Substring(0,values.ToString().IndexOf( ". "));
tempR=values.Substring(values.ToString().IndexOf( ". ")+1,values.ToString().Length-values.ToString().IndexOf( ". ")-1);
for(int i=tempR.Length-1;i> =1;i++)
{
if(tempR.Substring(i,1).ToString()== "0 ")
{
tempR=tempR.Substring(0,tempR.Length-1);
i=tempR.Length-2;
}
}
values=tempL.ToString()+ ". "+tempR.ToString();
}
catch
{
}
this.textBox1.Text=values.ToString();
------解决方案--------------------
dc.ToString( "G0 ")