I am using next code to format double value:
String.Format("${0:0,0.#}",...);
It working great, but when numbers are less than 10, I got problem. Numbers are displayed as $03, $06 for example.
Please advise me correct string to have a double number in next format ddd,ddd,ddd,ddd.dd
Try this instead:
If your double represents a currency you should use:
Note that if you omit the
CultureInfo.InvariantCultureit could display using something other than$on some computers. For example on my computerstring.Format("{0:c}", d)gives2,00 krwhich might not be what you wanted.In your example you don’t actually need to use
string.Formatat all. You could use this instead:As well as being clearer and more concise, it also has the advantage of avoiding boxing. Of course if your format string is more complex than in your example then it would make sense to use
string.Format.And as a final remark I’d recommend against using doubles to store currency. A decimal type is probably more appropriate.