Format decimal c# - Keep last zero

Viewed 10461

I have been searching for this but cannot seem to find the answer. I have the following decimals with the corresponding output that I want from String.Format

100.00 -> 100
100.50 -> 100.50
100.51 -> 100.51

My problem is that I cannot seem to find a format which will keep the 0 on the end of 100.50 as well as remove the 2 zeros from 100.

Any help is much appreciated.

EDIT For some more clarity. I have variables of type decimal, they are only ever going to be 2 decimal places. Basically I want to display 2 decimal places if they exist or none, I don't want to display one decimal place in the case of 100.50 becoming 100.5

5 Answers
Related