郑德才博客 记录学习,记录工作,学习知识分享!

将一个千以上的数字数据转换为使用‘,’分隔的字符串的方法

        /// <summary>

       /// 转换数字为使用‘,’分隔的字符串

       /// </summary>

       /// <param name="src">数字值</param>

       /// <returns>转换后的数字字符串</returns>

       public string ConvertInt(int src)

       {

           string result = "";

           if (System.Math.Abs(src) < 1000) //大于1000才需要转换,如果不是就不用转换直接得到字符串

               result = src.ToString();

           else

           {

               result = src.ToString().Substring(src.ToString().Length - 3, 3);

           }

           int quotient = src / 1000;

           if (System.Math.Abs(quotient) > 0)

           {

               result = ConvertInt(quotient) + "," + result;

           }

           return result;

       }

2013年3月20日 | 发布:郑德才博客 | 分类:工作之路 | 评论:0

发表留言: