Check if number is double or int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Check if number is double or int

    I need to check if a given number is an int or a double. I don't want to round doubles to ints, I just want to know if the number is an int or a double. Is there any way to do this?

    For the record, I start with an 2 ints, one is the width of an image and the other a number I'll be dividing the width by. I need to be able to find out if the width is divisible by the number I'm dividing it by evenly, otherwise I need to alert the client.

    Someone please help me.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    The modulus operator gives you the remainder of one number divided by another number. The operator is %.

    So...

    Code:
                Console.WriteLine(5 % 3);
                Console.WriteLine(10 % 3);
                Console.WriteLine(27 % 10);
                Console.WriteLine(15 % 3);
                Console.WriteLine(12 % 4);
    Outputs...
    7
    1
    7
    0
    0


    So when the modulus is zero, the numbers are evenly divisible and there is no fractional part.

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      I feel SO dumb. I just (literally, JUST) used MOD in php, I had an issue with a playlist in windows media player where I suddenly had a duplicate of every song, so I used mod to determine if the row number was even or odd and only pulled out the odd rows to remove the duplicates. I should have remembered this.

      Thank you, very much.

      Comment

      Working...