开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜