C#数字前面如何补0

PadLeft()函数:向左补齐
PadRight()函数:向右补齐

 class Program
    {
        static void Main(string[] args)
        {
            int a = 3;
            Console.WriteLine(a.ToString().PadLeft(3,'0'));   //向左补齐
            Console.WriteLine(a.ToString().PadRight(3, '0')); //向右补齐
            Console.ReadKey();
        }
    }

猜你喜欢

转载自www.cnblogs.com/cnwuchao/p/10586721.html