首页 > Windows开发 > 详细

C# 左右补零

时间:2019-04-08 10:09:25      阅读:140      评论:0      收藏:0      [点我收藏+]

//不够4位补零

        public static string addZero(int val)

        {

            string str = val + "";

            int strLen = str.Length;

            if (strLen < 4)

            {

                while (strLen < 4)

                {

                    StringBuilder sb = new StringBuilder();

                    sb.Append("0").Append(str);//左补0  

                    //sb.append(str).append("0");//右补0  

                    str = sb.ToString();

                    strLen = str.Length;

                }

            }

 

            return str;

        }

 

C# 左右补零

原文:https://www.cnblogs.com/z45281625/p/10668635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!