Author 
Message 
LowOrderBi #1 / 15

Lowest whole number
i am trying to get the lowest whole number from an eqaution. for example 407 / 160 = 2.54 i would like to have 407 / 160 return the value of 2 i tried round(407 / 160) but it returns 3. so, my question.. how can i force vb to round down no matter what the remainder is??? e0

Wed, 08 Dec 2004 06:45:10 GMT 


Modiglian #2 / 15

Lowest whole number
Try: 407 \ 160
Quote: > i am trying to get the lowest whole number from an eqaution. > for example > 407 / 160 = 2.54 > i would like to have 407 / 160 return the value of 2 > i tried round(407 / 160) but it returns 3. > so, my question.. > how can i force vb to round down no matter what the remainder is??? > e0

Wed, 08 Dec 2004 07:02:36 GMT 


LowOrderBi #3 / 15

Lowest whole number
yeah that works.. thx i also found that Fix(407 / 160) returns 2.. which do you think is better? e0
Quote: > Try: 407 \ 160
> > i am trying to get the lowest whole number from an eqaution. > > for example > > 407 / 160 = 2.54 > > i would like to have 407 / 160 return the value of 2 > > i tried round(407 / 160) but it returns 3. > > so, my question.. > > how can i force vb to round down no matter what the remainder is??? > > e0

Wed, 08 Dec 2004 07:05:38 GMT 


Modiglian #4 / 15

Lowest whole number
Fix is necessary if you might have very large numbers (larger than a long).
Quote: > yeah that works.. thx > i also found that > Fix(407 / 160) > returns 2.. > which do you think is better? > e0
> > Try: 407 \ 160
> > > i am trying to get the lowest whole number from an eqaution. > > > for example > > > 407 / 160 = 2.54 > > > i would like to have 407 / 160 return the value of 2 > > > i tried round(407 / 160) but it returns 3. > > > so, my question.. > > > how can i force vb to round down no matter what the remainder is??? > > > e0

Wed, 08 Dec 2004 08:46:09 GMT 


Rick Rothstei #5 / 15

Lowest whole number
Quote: > Fix is necessary if you might have very large numbers (larger than a
long). Huh??? From the VB Help files: Both Int and Fix remove the fractional part of number and return the resulting integer value. The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. To the Original Poster: The backslash performs integer division. A\B is identical to Int(A/B). Rick

Wed, 08 Dec 2004 11:26:24 GMT 


Nick Palmiu #6 / 15

Lowest whole number
I'd say use the Fix() method, mainly because it improves readability. Kind Regards Nick Palmius
Quote: > > Fix is necessary if you might have very large numbers (larger than a > long). > Huh??? > From the VB Help files: > Both Int and Fix remove the fractional part of number and return the > resulting integer value. > The difference between Int and Fix is that if number is negative, Int > returns the first negative integer less than or equal to number, whereas > Fix returns the first negative integer greater than or equal to number. > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > To the Original Poster: The backslash performs integer division. > A\B is identical to Int(A/B). > Rick

Thu, 09 Dec 2004 06:06:02 GMT 


Rick Rothstei #7 / 15

Lowest whole number
I'm not sure I'd agree that Fix is any more readable than Int is. However, if that is your feeling, fine...as long as you are dealing with positive numbers only. For negative numbers, the difference between Fix and Int (or its equivalent backslash representation) is significant. Rick
Quote: > I'd say use the Fix() method, mainly because it improves readability. > Kind Regards > Nick Palmius
> > > Fix is necessary if you might have very large numbers (larger than a > > long). > > Huh??? > > From the VB Help files: > > Both Int and Fix remove the fractional part of number and return the > > resulting integer value. > > The difference between Int and Fix is that if number is negative, Int > > returns the first negative integer less than or equal to number, whereas > > Fix returns the first negative integer greater than or equal to number. > > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > > To the Original Poster: The backslash performs integer division. > > A\B is identical to Int(A/B). > > Rick

Thu, 09 Dec 2004 09:41:36 GMT 


Nick Palmiu #8 / 15

Lowest whole number
Quote: > I'm not sure I'd agree that Fix is any more readable than Int is. > However, if that is your feeling, fine...as long as you are dealing with > positive numbers only. For negative numbers, the difference between Fix > and Int (or its equivalent backslash representation) is significant.
Fair enough, using Int or Fix makes no significant difference to readability, however, the \ sign is very easily mistaken for / , for obvious reasons, which is what I meant. Nick Palmius Quote: > Rick
> > I'd say use the Fix() method, mainly because it improves readability. > > Kind Regards > > Nick Palmius
> > > > Fix is necessary if you might have very large numbers (larger than > a > > > long). > > > Huh??? > > > From the VB Help files: > > > Both Int and Fix remove the fractional part of number and return the > > > resulting integer value. > > > The difference between Int and Fix is that if number is negative, > Int > > > returns the first negative integer less than or equal to number, > whereas > > > Fix returns the first negative integer greater than or equal to > number. > > > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > > > To the Original Poster: The backslash performs integer division. > > > A\B is identical to Int(A/B). > > > Rick

Thu, 09 Dec 2004 10:03:08 GMT 


Randy Birc #9 / 15

Lowest whole number
But integer division ( \ ) is faster than floating point ( / ) or calling a secondary function (Fix).  Randy Birch MVP Visual Basic http://www.mvps.org/vbnet/ Please respond only to the newsgroups so all can benefit.
Quote:
> > I'm not sure I'd agree that Fix is any more readable than Int is. > > However, if that is your feeling, fine...as long as you are dealing with > > positive numbers only. For negative numbers, the difference between Fix > > and Int (or its equivalent backslash representation) is significant. > Fair enough, using Int or Fix makes no significant difference to > readability, however, the \ sign is very easily mistaken for / , for obvious > reasons, which is what I meant. > Nick Palmius > > Rick
> > > I'd say use the Fix() method, mainly because it improves readability. > > > Kind Regards > > > Nick Palmius
> > > > > Fix is necessary if you might have very large numbers (larger than > > a > > > > long). > > > > Huh??? > > > > From the VB Help files: > > > > Both Int and Fix remove the fractional part of number and return the > > > > resulting integer value. > > > > The difference between Int and Fix is that if number is negative, > > Int > > > > returns the first negative integer less than or equal to number, > > whereas > > > > Fix returns the first negative integer greater than or equal to > > number. > > > > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > > > > To the Original Poster: The backslash performs integer division. > > > > A\B is identical to Int(A/B). > > > > Rick

Thu, 09 Dec 2004 10:12:53 GMT 


Rick Rothstei #10 / 15

Lowest whole number
Quote: > Fair enough, using Int or Fix makes no significant difference to > readability, however, the \ sign is very easily mistaken for / , for obvious > reasons, which is what I meant.
I kinda suspected that, but you made a direct suggestion to (always<==implied) use the Fix function. I just wanted to point out that Int and \ are identically equivalent for *all* numbers whereas the Fix function and \ are equivalent for only the *positive* numbers (and, hence, can produce different results for the negative numbers). Rick

Thu, 09 Dec 2004 10:15:40 GMT 


Nick Palmiu #11 / 15

Lowest whole number
Quote: > > Fair enough, using Int or Fix makes no significant difference to > > readability, however, the \ sign is very easily mistaken for / , for > obvious > > reasons, which is what I meant. > I kinda suspected that, but you made a direct suggestion to > (always<==implied) use the Fix function. I just wanted to point out that > Int and \ are identically equivalent for *all* numbers whereas the Fix > function and \ are equivalent for only the *positive* numbers (and, > hence, can produce different results for the negative numbers). > Rick
Yeah, It all depends on the situation I think, BUT as Randy said, Integer Division is faster than Floating point (Though not really noticable unless on a very large scale), and with it working for negative numbers too, it will probably be more usefull all round. I stand corrected. However, there will always be situations where Fix() will be more usefull, such as where you want negative numbers converted to positive, But I don't really think that that was the issue here. Kind Regards Nick Palmius

Thu, 09 Dec 2004 10:26:58 GMT 


Modiglian #12 / 15

Lowest whole number
Quote: >> A\B is identical to Int(A/B).
Not quite. Try it with A = 99999999999 A \ B gives an overflow error. Int and Fix do not.
Quote: > > Fix is necessary if you might have very large numbers (larger than a > long). > Huh??? > From the VB Help files: > Both Int and Fix remove the fractional part of number and return the > resulting integer value. > The difference between Int and Fix is that if number is negative, Int > returns the first negative integer less than or equal to number, whereas > Fix returns the first negative integer greater than or equal to number. > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > To the Original Poster: The backslash performs integer division. > A\B is identical to Int(A/B). > Rick

Thu, 09 Dec 2004 15:51:30 GMT 


Rick Rothstei #13 / 15

Lowest whole number
You are right..."identical" was a stretch. However, they are functionally identical to within the ranges allowed by their arguments. The backslash takes values up to the maximum allowed for a Long for each of its arguments whereas the arguments for Int and Fix seem to work up to the maximum allowed for a Double if "normal* variable types are used and up to that for a Decimal data type if a Variant variable is used which has been cast as a Decimal. Rick
Quote: > >> A\B is identical to Int(A/B). > Not quite. Try it with A = 99999999999 > A \ B gives an overflow error. Int and Fix do not.
> > > Fix is necessary if you might have very large numbers (larger than a > > long). > > Huh??? > > From the VB Help files: > > Both Int and Fix remove the fractional part of number and return the > > resulting integer value. > > The difference between Int and Fix is that if number is negative, Int > > returns the first negative integer less than or equal to number, whereas > > Fix returns the first negative integer greater than or equal to number. > > For example, Int converts 8.4 to 9, and Fix converts 8.4 to 8. > > To the Original Poster: The backslash performs integer division. > > A\B is identical to Int(A/B). > > Rick

Thu, 09 Dec 2004 16:22:14 GMT 


Joe #14 / 15

Lowest whole number
Quote:
> i am trying to get the lowest whole number from an eqaution. > for example > 407 / 160 = 2.54 > i would like to have 407 / 160 return the value of 2 > i tried round(407 / 160) but it returns 3. > so, my question.. > how can i force vb to round down no matter what the remainder is???
Round "down", or round towards zero? It matters mainly when there might be negative numbers involved. How large and how small could the numbers be?  Joe Foster <mailto:jlfoster%40znet.com> On the cans? <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!

Fri, 10 Dec 2004 10:34:49 GMT 


Philipp #15 / 15

Lowest whole number
Hello, Try to use n = Int(407/160) Have a good day, Philippe. Quote: >Original Message
Quote: >> i am trying to get the lowest whole number from an eqaution. >> for example >> 407 / 160 = 2.54 >> i would like to have 407 / 160 return the value of 2 >> i tried round(407 / 160) but it returns 3. >> so, my question.. >> how can i force vb to round down no matter what the remainder is??? >Round "down", or round towards zero? It matters mainly when there might >be negative numbers involved. How large and how small could the numbers >be? > >Joe Foster <mailto:jlfoster%40znet.com> On the cans?
<http://www.xenu.net/> Quote: >WARNING: I cannot be held responsible for the
above They're coming to Quote: >because my cats have apparently learned to
type. take me away, ha ha! Quote:

Fri, 10 Dec 2004 17:52:14 GMT 

