.NET supports two types of string formatting.
I’m in a situation where existing configuration data has #,##0 style formatting. A new feature requires formatting to the same output, but the API needed for this feature only accepts formatting of type {0:n2}.
Does anyone know of a means to convert between these two representations for numeric types? DateTime can be ignored.
EDIT I’ve learned that:
-
The
{0:n2}style is known as standard numeric formatting -
The
#,##0style is known as custom numeric formatting
No, you can’t.
From your link to the MSDN articles about standard format strings, you’ll find:
So the standard formatting specifiers will vary depending on which culture the program is running under.
Since your custom formating specifies exactly how the number is going to look, whatever the culture the program is running under. Its allways gonna look the same.
The culture the program is running under isn’t known during compile time, it’s a runtime property.
So the answer is: No, you can’t map automatically, because there isn’t a one-to-one consistent mapping.