Another String.Format() Question

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
 
G

Guest

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
 
G

Guest

Small bug - double quotes :)

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

Pozdro Tomek :D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top