5

Possible Duplicate:
Display Float as String with at Least 1 Decimal Place

Given the following values:

  • 23.50
  • 15
  • 19.3500
  • 31.505
  • 45.6670

How can I achieve the following display:

  • 23.50
  • 15.00
  • 19.35
  • 31.505
  • 45.667

What I am trying to do is force 2 decimal places UNLESS there are more "significant" digits, in which case I'd like to show them as well.

Note: The value is currently stored as a Decimal?

Community
  • 1
  • 1
Brian David Berman
  • 6,920
  • 23
  • 74
  • 143

1 Answers1

7

Use

yourNumber.ToString(".00######")
lante
  • 6,736
  • 2
  • 31
  • 56