Results 1 to 29 of 29

Thread: division?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    division?

    if i divide 10 / 4 ill get a 2 when i should get a 2,5..in vb if we did 10 \ 4 we'd get a 2,5 and if we did 10 / 4 we'd get a 2...but how do i do the \ in C#? i noticed the MOD operator doesnt exist in C# too =\

  2. #2

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i saw on msdn and it says the / is overloaded...but how da hell do i do to make that when i want it to have decimal and not decimal then?

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    When integers are used with arithmetic operators, an integer is returned and any remainder is discarded. When floating-point numbers are used with arithmetic expressions, a floating-point number is returned.

    Code:
    static void Main(string[] args)
    {
    	double returnVal = 0;
    	returnVal = (10 / 4f);
    	Console.WriteLine(returnVal);
    }
    Also, the mod operator is: %

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    PHP Code:
                int iMax nTab.Width IMAGE_WIDTH;
                
    MessageBox.Show(iMax.ToString()); 
    what do i do?

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You are assigned the result to an integer. Do you want a whole number or floating-point #?

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm i dont get what u mean...nTab = 777 and IMAGE_WIDTH is 115...i want it to return 6,7565217391304347826086956521739

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Code:
       double dMax = (nTab.Width / IMAGE_WIDTH);

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah it has to be a double?

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    not working dude

  10. #10
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yep, integral numbers discard any decimal values.

  11. #11
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    what is the return?

  12. #12

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah so 1st i must convert all the values to double right?

  13. #13

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    is 6 lol

  14. #14
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You must be working with integer types. Assign them to double variables.

  15. #15

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea worked now :

    PHP Code:
                double val1 nTab.Widthdouble val2 IMAGE_WIDTH;
                
    double iMax = (val1 val2);
                
    MessageBox.Show(iMax.ToString()); 
    isnt there a way that i can do like in vb.net CTYPE(converttype) CTYPE(nTab.Width,wished type) ?

  16. #16
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You will have to cast the variable to the desired type.
    ( Type Goes Here.. )

    Code:
        double myDouble = (double) nTab.Width;

  17. #17

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah casting is the equivalent to the VB Ctype()?

  18. #18
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    That's what CType() does..It converts a variables type to a different type.

  19. #19

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea but i didnt know casting was the same thing lolol

  20. #20
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's another way just for reference:

    Code:
    {
    	int width = 777, height = 100;
    	float result = ((float)width / (float)height);
    	Console.WriteLine(result);
    }

  21. #21

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    what the difference between float,double and integer? and longs? and int16 int32 int64?

  22. #22
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    There are eight integral types you can use to represent whole or integer numbers:
    sbyte, byte, short, ushort, int, uint, long, ulong

    As you can see, each type has a signed and unsigned version of the type.

    Then we have floating-point types. There are three floating-point types you can use to represent floating-point numbers:
    floag, double, decimal

    These allow for n # of places after the decimal (precision).

  23. #23

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    thats the theory..but why do ppl use ints and not shorts? or uints? or sbyts?

  24. #24
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Well, each types takes up a different amount of memory when stored on the stack. Don't u agree its a waste to store the number 5 into a long when a byte type would suffice?
    Last edited by Lethal; Oct 26th, 2002 at 05:43 PM.

  25. #25

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm...int suports how much memory? 32? and this means what? it can handle up to 32 chars?

  26. #26
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    32 bits, which is equivalent = -2,147,483,647 to 2,147,483,647 (signed)

  27. #27

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    isnt there a table around there to see from where to where go that values lol?

  28. #28
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yeah, I'm actually getting ready to leave for a costume party, so do a search and I'm sure you'll find all your looking for.

  29. #29

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea i believe so tks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width