Ian (Fluxtah) Warwick's blog RSS 2.0
# Wednesday, November 25, 2009

I was thinking about this, for some reason, and thought it would be good to remind myself of those little useful bits of code that you never really use much then sometimes wonder how to do them.

So my first tidbit, is to test if a number is a whole number, here is my solution, any better solution than this, answers on a postcard please.

void Main()
{
    decimal decimalNumber = 4.9M;
    decimal wholeNumber = 5;
    
    Console.WriteLine(Math.Floor(decimalNumber) == decimalNumber); // Returns false;
    Console.WriteLine(Math.Floor(wholeNumber) == wholeNumber); // Returns true;
}

 

Wednesday, November 25, 2009 10:39:40 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
C#
Comments are closed.
Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Ian Warwick
Sign In
Statistics
Total Posts: 33
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2012, Ian Warwick
DasBlog theme 'Business' created by Christoph De Baene (delarou)