Author: turash | Posted on: 3/5/2010 12:51:07 PM | Views : 481

What is the best way to format a decimal if I only want decimal displayed if it is not an integer.

Eg:

decimal amount = 1000M
decimal vat = 12.50M
Decimal test = 0.00008

When formatted I want:

Amount: 1000 (not 1000.0000)
Vat: 12.5 (not 12.50)
test : 0.00008

The best solution i came across till now is

Decimal.ToString("G29")

but this fails for last example unless i use this "0.#############################"

Some detail discussion on this article
http://msdn.microsoft.com/en-us/netframework/aa569607.aspx


any one has experinced simillar issue? so G29 is not best option?


Thanks in advance
Tushar


...

Go to the complete details ...