Old question but I wanted to add the simplest option in my opinion.
Without thousands separators:
value.ToString(value % 1 == 0 ? "F0" : "F2")
With thousands separators:
value.ToString(value % 1 == 0 ? "N0" : "N2")
The same but with String.Format:
String.Format(value % 1 == 0 ? "{0:F0}" : "{0:F2}", value) // Without thousands separators
String.Format(value % 1 == 0 ? "{0:N0}" : "{0:N2}", value) // With thousands separators
If you need it in many places, I would use this logic in an extension method:
public static string ToCoolString(this decimal value)
{
return value.ToString(value % 1 == 0 ? "N0" : "N2"); // Or F0/F2 ;)
}