how to transfer C++ number format to C# number format?
have the flowing C++ code:
CString info, info2;
info.Format("%2d", Value[i]);
info2.Format("%4.1f", Value[j]);
want to have the equivalent code in C#
开发者_运维技巧how to do it?
Code ported to C#:
String info;
String info2;
info = String.Format("{0,2:D}", Value[i]);
info2 = String.Format("{0,6:0.0}", Value[j]);
6 is used for aligning the string 4 digits plus decimal point plus decimal digit.
NOTE take care of the current Culture used, you might get ,
instead of .
for some Cultures.
Value[i].ToString("D");
Value[j].ToString("####.0");
精彩评论