S statik213 Golden Member Oct 31, 2004 1,654 0 0 Feb 2, 2006 #1 I'm doing this right now: double d; if(d > (long) d) // has a decimal potion else // is an integer is there a better a way?
I'm doing this right now: double d; if(d > (long) d) // has a decimal potion else // is an integer is there a better a way?
N notfred Lifer Feb 12, 2001 38,241 4 0 Feb 2, 2006 #2 I would have done this: double d; if((int)d == d){ //stuff } else{ //other stuff } Your code doesn't work with negative numbers.
I would have done this: double d; if((int)d == d){ //stuff } else{ //other stuff } Your code doesn't work with negative numbers.
A Argo Lifer Apr 8, 2000 10,045 0 0 Feb 2, 2006 #3 You can use modulus operator (%) with doubles as well. double d; if (d % 1.0 > 0) // We have decimal part.
You can use modulus operator (%) with doubles as well. double d; if (d % 1.0 > 0) // We have decimal part.
S statik213 Golden Member Oct 31, 2004 1,654 0 0 Feb 2, 2006 #4 Originally posted by: notfred I would have done this: double d; if((int)d == d){ //stuff } else{ //other stuff } Your code doesn't work with negative numbers. Click to expand... ok, didnt think of that
Originally posted by: notfred I would have done this: double d; if((int)d == d){ //stuff } else{ //other stuff } Your code doesn't work with negative numbers. Click to expand... ok, didnt think of that