.net standard format specifier to equivalent custom format
Is it possible to convert a standard number format specifier into it's equivalent custom format, e.g. n2
depending on the current culture might be #,##0.00
.
Basically is there a function that converts one to the other?
Thanks,
I can't find one line solution to format as #,##0.00
. Adding an extra 0
after 3 digits causing the issue, so I did split this task in extra steps and format looks as #,###.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));
精彩评论