Is there a difference for division when you use "/" or "\"?
Printable View
Is there a difference for division when you use "/" or "\"?
The \ returns an Integer, whereas the / returns a floating-point.
yes there is, but what exactly do you mean? those 2 chars use to show up here and there in the IT world.
Yes Matthew, there is a difference.
The backslash must return an integer and it rounds numbers.
e.g 2.5 \ 1.5 rounds to 3\2 or 1.5 which is then rounded to 1. In other words it returns how many 1.5's are in 2.5 in whole numbers, answer - only 1.
I hope I explained that right, but that's basically how it works
GRAHAM :)
What do you mean when you say that?Quote:
Originally posted by Megatron / floating-point
It means that there will be decimals at the end.
Get what I mean?Code:45 \ 6 = 7
45 / 6 = 7.5
Yup, I understand. It's like this:
Code:45 \ 6 = 7 = (rounded)
45 / 6 = 7.5 = (exact)
but the \ operator is HEAPS quicker.
if you have a loop with intensive math, you're better off multiplying your 3 dec vars by 1000, holding them in Long's and using the \ type. the overhead to calculate floating points, singles and doubles is very high.
and it's not rounded!
100 goes into 99 zero times, it never rounds up.
99 / 100 = 0.99
99 \ 100 = 0
which is why it's faster, it doesn't calculate the modulus
[Edited by Paul282 on 05-31-2000 at 08:53 PM]
There's a subtle point to what the good people here say relative to the / and \ operators. It's very easy to unwittingly declare an integer, long or byte datatype and then via VB's weak type-casting, waste a huge amount of CPU cycles doing floating-point arithmetic.
For example:
Code:Dim X AS Integer
X = 7/3 ' bad kitty method
' processor does backflips to return 2.33333
' which is then type-cast to a result of 2