문제

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?

도움이 되었습니까?

해결책

Use

yourNumber.ToString(".00######")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top