I am looking for a format to use with string.Format that would print the following
double d = 123456.123456D;
double d2 = 123456D;
like
123,456.123456
123,456
{0:N6} results in
123,456.123456
123,456.000000
{0:0.######} results in
123456.123456
123456
{0:#.0} results in
123,456
123,456
I cannot workout a format that will get me to what I need. Will I need to define my own format provider ?
Multiply by 1. A better way to remove trailing zeros is to multiply by 1 . This method will remove trailing zeros from the decimal part of the number, accounting for non-zero digits after the decimal point. The only downside is that the result is a numeric value, so it has to be converted back to a string.
You're close. Use this format:
{0:#,0.######}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With