How to determine if a decimal/double is an integer?

Posted by Jim Geurts on Stack Overflow See other posts from Stack Overflow or by Jim Geurts
Published on 2010-05-01T21:25:25Z Indexed on 2010/05/01 21:27 UTC
Read the original article Hit count: 199

Filed under:

How do I tell if a decimal or double is an integer?

For example:

decimal d = 5.0; // Would be true
decimal f = 5.5; // Would be false

or

double d = 5.0; // Would be true
double f = 5.5; // Would be false

The reason I would like to know this, is so that I can determine programmatically if I want to output the value using .ToString("N0") or .ToString("N2"). If there is no decimal point value, then I don't want to show that.

© Stack Overflow or respective owner

Related posts about c#