Pregunta

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?

¿Fue útil?

Solución

Use

yourNumber.ToString(".00######")
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top