Is it possible to define a default number format that is used whenever I convert an integer
(or double
etc.) to a String
without specifying a format string?
C# example:
int i = 123456;
string s = "Hello " + i;
// or alternatively with string.Format without format definition
string s = string.Format("Hello {0}", i);
ASP.NET Razor example:
<div>
Hello @i
</div>
I think all these code lines implicitly use the default ToString()
method for Int32
. And not surprisingly, all these code lines result in "Hello 123456"
, but I want "Hello 123,456"
.
So can I specify that "N0"
should be used by default (at least for integer
)?
I already found the question Set Default DateTime Format c# - it looked good, but it doesn't help me for numbers.
Edit: I'm aware that I could write an extension method which I can use throughout my application, but this is not what I'm looking for. I would like to find a property (maybe somewhere hidden in CultureInfo
or NumberFormatInfo
) which is currently set to "G"
and is used by the default Int32.ToString()
implementation.