Need to format a nullable decimal in C#

Mannsi used Ask the Experts™
Hello experts,

I'm having what I consider a silly problem. I have a decimal? value in c# that I would like to format. It currently displays as 40.00000 but I would like to see 40.00. If the decimal value happens to be null I would like to see either a 0 or nothing.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
apart from the nullable:

so, I would suggest:
string result = value == null ? "0" : String.Format("{0:0.00}", value);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial