16

Possible Duplicate:
Double.ToString with N Number of Decimal Places

I want to show a decimal to 6 decimal places, even if it contains 6 x 0's For example:

3.000000
5.100000
3.456789

and so forth, is this possible?

Community
  • 1
  • 1
CallumVass
  • 11,288
  • 26
  • 84
  • 154
  • 2
    Check http://www.csharp-examples.net/string-format-double/ - I'm sure this has been asked many times before though – ChrisF Dec 07 '11 at 09:20
  • 2
    One: http://stackoverflow.com/questions/3359916/format-to-two-decimal-places. Two: http://stackoverflow.com/questions/4884749/format-a-double-to-8-decimal-places. Three: http://stackoverflow.com/questions/5168592/force-a-string-to-2-decimal-places. – Iarek Dec 07 '11 at 09:21

2 Answers2

54

Use N6 as the numeric format string.

myDecimal.ToString("N6");

or

string.Format("{0:N6}", myDecimal);
Joey
  • 344,408
  • 85
  • 689
  • 683
  • The problem with that is, that is converts it to a string, i need to keep it in a decimal format, as that is the datatype stored in the database. – CallumVass Dec 07 '11 at 09:31
  • 2
    @BiffBaffBoff What you want looks strange because decimal format has nothing to do with its formatted output. – Iarek Dec 07 '11 at 10:11
7
Decimal d = 20;
d.ToString("0.000000");
Russell Troywest
  • 8,635
  • 3
  • 35
  • 40