C# 字符串去掉后面多余的零

 1    /// <summary>
 4     /// 去除后面多余的零
 5     /// </summary>
 6     /// <param name="dValue"></param>
 7     /// <returns></returns>
 8     private string RemoveZero(decimal dValue)
 9     {
10         string sResult = dValue.ToString();
11         if (sResult.IndexOf(".") < 0)
12             return sResult;
13         int iIndex = sResult.Length - 1;
14         for (int i = sResult.Length - 1; i >= 0; i--)
15         {
16             if (sResult.Substring(i, 1) != "0")
17             {
18                 iIndex = i;
19                 break;
20             }
21         }
22         sResult = sResult.Substring(0, iIndex + 1);
23         if (sResult.EndsWith("."))
24             sResult = sResult.Substring(0, sResult.Length - 1);
25         return sResult;
26     }

 

 

posted @ 2012-04-28 10:07  看看天上云  阅读(3108)  评论(0编辑  收藏  举报