开发者

how to transfer C++ number format to C# number format?

开发者 https://www.devze.com 2023-01-04 11:37 出处:网络
have the flowing C++ code: CString info, info2; info.Format(\"%2d\", Value[i]); info2.Format(\"%4.1f\", Value[j]);

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

精彩评论

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