Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .net标准格式说明符转换为等效的自定义格式_C#_.net - Fatal编程技术网

C# .net标准格式说明符转换为等效的自定义格式

C# .net标准格式说明符转换为等效的自定义格式,c#,.net,C#,.net,是否可以将标准数字格式说明符转换为其等效的自定义格式,例如,n2(取决于当前区域性)可能是,#0.00 基本上有一个函数可以将一个转换为另一个吗 谢谢 AJ我找不到一行格式为,##0.00的解决方案。在导致问题的3位数字后添加一个额外的0,因此我将此任务分成了额外的步骤,格式看起来是,###.00 int n2 = 123; // adding extar '0' at the end string result = String.Format("{0}", n2).PadRight(4, '

是否可以将标准数字格式说明符转换为其等效的自定义格式,例如,
n2
(取决于当前区域性)可能是
,#0.00

基本上有一个函数可以将一个转换为另一个吗

谢谢


AJ

我找不到一行格式为
,##0.00
的解决方案。在导致问题的3位数字后添加一个额外的
0
,因此我将此任务分成了额外的步骤,格式看起来是
,###.00

int n2 = 123;

// adding extar '0' at the end
string result = String.Format("{0}", n2).PadRight(4, '0');

// convert result back to int.
n2 = Int32.Parse(result);

// Format: #,###.00
Console.WriteLine("Format: #,###.00 \t" + 
                   n2.ToString("0,0.00", CultureInfo.InvariantCulture));

我找不到一行格式为
,##0.00
的解决方案。在导致问题的3位数字后添加一个额外的
0
,因此我将此任务分成了额外的步骤,格式看起来是
,###.00

int n2 = 123;

// adding extar '0' at the end
string result = String.Format("{0}", n2).PadRight(4, '0');

// convert result back to int.
n2 = Int32.Parse(result);

// Format: #,###.00
Console.WriteLine("Format: #,###.00 \t" + 
                   n2.ToString("0,0.00", CultureInfo.InvariantCulture));

您查看过NumberFormatInfo类吗?是的,但没有看到任何可能有用的内容。在.NET中似乎不存在这样的函数。您可以使用NumberFormatInfo的所有属性编写自己的函数。您查看过NumberFormatInfo类吗?是的,我查看过,但看不到任何有帮助的内容。在.NET中似乎不存在这样的函数。您可以使用NumberFormatInfo的所有属性编写自己的代码。