TrimZero方法

 

        /// <summary>
        
/// 把数值末位的0去掉
         
/// </summary>
        
/// <param name="originalNumber"></param>
        
/// <returns></returns>
        public string TrimZero(decimal originalNumber)
        {
            
string result = System.Text.RegularExpressions.Regex.Replace(originalNumber.ToString(), @"(\.\d+?)[0]+$""$1");
            
return System.Text.RegularExpressions.Regex.Replace(result, @"\.0$""");
        }

        
/// <summary>
        
/// 把数值末位的0去掉
         
/// </summary>
        
/// <param name="originalNumber"></param>
        
/// <returns></returns>
        public string TrimZero(string originalNumber)
        {
            
if (CommonFunction.CheckDecimal(originalNumber))
            {
                
string result = System.Text.RegularExpressions.Regex.Replace(originalNumber, @"(\.\d+?)[0]+$""$1");
                
return System.Text.RegularExpressions.Regex.Replace(result, @"\.0$""");
            }
            
else
            {
                
return "0";
            }
        }

posted on 2009-02-03 15:57  Sammy  阅读(458)  评论(0编辑  收藏  举报

导航