C# string formatting and padding

后端 未结 2 1526
青春惊慌失措
青春惊慌失措 2021-01-19 05:15

Seems like this should be something straightforward, but I haven\'t been able to get it right. I\'ve looked at http://idunno.org/archive/2004/14/01/122.aspx for reference.

2条回答
  •  心在旅途
    2021-01-19 05:42

    Try

    double d = 3.14;
    Console.WriteLine("{0,10:0.000}", d);
    

    P.S: have a look at this article as a primer on string formatting. Also, string.Format should allow you doing everything sprintf does - and actually more... what else are you trying to do?

提交回复
热议问题