Another String.Format() Question

  • Thread starter Thread starter thomas
  • Start date Start date
T

thomas

Hello Everyone,

I am trying to format decimal values the way so decimal point is display
only if the number is any digits after decimal other than zero.

Example:
9.000000 -> "9"
9.500000 -> "9.5"

Does anyone have an idea how the format string should look like? Is it, at
all, possible?

Tomasz
 
Bryan,

No need for that. He may use:

decimal x = 19.5M;
string formatedValue = x.ToString(""0.########"");

For more information check MSDN for 'Custom Numeric Format Strings'.
Hope this helps
 
Small bug - double quotes :)

it should be:
decimal x = 19.5M;
string formatedValue = x.ToString("0.########");

Pozdro Tomek :D
 
Back
Top