Reputation: 1139
I have some double values I want to convert to a string with this pattern:
0.xx or x.xx
Currently I have try this:
double.ToString("#.#0");
What should I add in order to see zero in case my number start with zero?
Upvotes: 21
Views: 49665
Reputation: 375
myDouble.ToString("N2")
should also work.
Have a look at
MSDN: Custom Numeric Format Strings
MSDN: Standard Numeric Format Strings
Upvotes: 8
Reputation: 700382
Put a zero in front of the decimal separator:
double.ToString("0.#0");
This will always include the digit, in contrast to #
which makes it optional.
Upvotes: 3