Frage

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?

War es hilfreich?

Lösung

just use

myDouble.ToString("0.00")

that should do the trick

Andere Tipps

myDouble.ToString("N2")

should also work.

Have a look at

MSDN: Custom Numeric Format Strings

MSDN: Standard Numeric Format Strings

String.Format("{0:0.00}", 111.0);

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.

use following :

myDouble.ToString("N2")
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top