커뮤니티
WSC Info.
제목:    string.format() c#
  2554   김윤중

string.Format(”0:00.00”,9.91234) => 09.91

 string d="9.1234";
            string s = d.ToString().PadLeft(4); // 9.1234
            s = string.Format("{0:00.00}", d);  //9.1234
            s = string.Format("{0:000.000}", 9.1234); //009.123
            s = string.Format("{0:.000}", 9.1234); //9.123
            s = string.Format("{0:00.}", 9.1234); //09
            s = string.Format("{0:00.00}", 9.1234).ToString().PadLeft(8); //  09.12

[C#]
String.Format("{0,5}", 15);              // "   15"
String.Format("{0,-5}", 15);             // "15   "
String.Format("{0,5:000}", 15);          // "  015"
String.Format("{0,-5:000}", 15);         // "015  "

String.Format("{0:#;minus #}", 15);      // "15"
String.Format("{0:#;minus #}", -15);     // "minus 15"
String.Format("{0:#;minus #;zero}", 0);  // "zero"

String.Format("{0:+### ### ### ###}", 447900123456); // "+447 900 123 456"
String.Format("{0:##-####-####}", 8958712551);       // "89-5871-2551"

See also