-5

Possible Duplicate:
How to format a decimal

I need to format a decimal like the following:

63.000 -> 63
63.045 -> 63.045
63.020 -> 63.02

But look at above, check the first one, if in decimal part there are only zeros, I need to remove those zeros for just 63.

Community
  • 1
  • 1
Darf
  • 2,495
  • 5
  • 26
  • 37

3 Answers3

0

String.Format would work for you, and the pattern "{0:0.###}" would work for all 3 of your cases.

String.Format("{0:0}", 63.000); 
String.Format("{0:0.###}", 63.045); 
String.Format("{0:0.##}", 63.02); 
Nix
  • 57,072
  • 29
  • 149
  • 198
0

Off the top of my head,

string.Format("{0:0.###}");
tomfanning
  • 9,552
  • 4
  • 50
  • 78
0

// max. three decimal places

String.Format("{0:0.###}", 63.000);      // "63"
String.Format("{0:0.###}", 63.045);         // "63.045"
String.Format("{0:0.###}", 63.02);         // "63.02"
Ben.Vineyard
  • 1,149
  • 8
  • 14