Dan*_*Dan -3 c# string format string-formatting
我目前在一个小型的C#程序中有以下多项.
long one = 1;
long two = 1005;
long three = 100000005;
long four = 1111112258552;
Run Code Online (Sandbox Code Playgroud)
我想将它们格式化为一个字符串,这样它们就是大小的千分之一,而不是将值除以千.
例
Input : Output
1 0.001
1005 1.005
100000005 100000.005
1111112258552 1111112258.552
Run Code Online (Sandbox Code Playgroud)
我已经尝试了字符串格式,例如{0:0,000},{0:0.000}但是没有提供我之后的结果.
我怎样才能达到我追求的结果?任何提示或指示将不胜感激
一些示例代码
long one = 1;
long two = 1005;
long three = 100000005;
long four = 1111112258552;
string format = "{0:0,000}";
string s1 = String.Format(format, one);
string s2 = String.Format(format, two);
string s3 = String.Format(format, three);
string s4 = String.Format(format, four);
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
Console.WriteLine(s4);
Run Code Online (Sandbox Code Playgroud)
尝试使用"{0:0,.000}"作为格式.
long one = 1;
long two = 1005;
long three = 100000005;
long four = 1111112258552;
string format = "{0:0,.000}";
string s1 = String.Format(format, one);
string s2 = String.Format(format, two);
string s3 = String.Format(format, three);
string s4 = String.Format(format, four);
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
Console.WriteLine(s4);
Run Code Online (Sandbox Code Playgroud)
控制台输出:
0.001
1.005
100000.005
1111112258.552
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |