How do I get a number formatted, such that the (culture-specific) thousands separator is also used after the decimal point?
Check this code (NUnit test case, passes as-is):
[Test]
[SetCulture("en-US")]
public void FormattingOnly()
{
// a large number
double result = 1E9 + 0.212324;
string printout = result.ToString("N9");
// Would like to have this as "1,000,000,000.212,320,000"
Assert.AreEqual("1,000,000,000.212320000", printout);
result = 0.212324;
printout = result.ToString("N9");
// Hard to read, should better be "0.212,324,000"
Assert.AreEqual("0.212324000", printout);
result = 0.212324;
printout = result.ToString("E9");
// Even harder to read, needs users to have a PhD ;)
Assert.AreEqual("2.123240000E-001", printout);
result = 1E9 + 0.212324;
printout = result.ToString("E");
// Completely worthless for many users
Assert.AreEqual("1.000000E+009", printout);
}
I'm trying to find the most readable form, that even users without a math background can understand. In my application, users have the possibility to set the number of digits in output formatting according to their needs.
Note: this is not a duplicate of .NET String.Format() to add commas in thousands place for a number. There it's about thousands separators in general.