Re: Decimal Display

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The VB Mod function only works with integral values, and it Rounds (using Banker's Rounding) and number containing fractions BEFORE it performs the Mod operations.

Where were you in the Fractional Remainder thread when I asked someone to confirm that Mod was integer-only? ;-)

If you type Mod in the IDE and hit F1, you'll see this at the bottom of that page.

<quote>
The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the following expression, A (result) equals 5.

A = 19 Mod 6.7

Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Variant containing a Long, regardless of whether or not result is a whole number. Any fractional portion is truncated. However, if any expression is Null, result is Null. Any expression that is Empty is treated as 0.
</quote>

I like how casually they say "rounding floating-point numbers"... the Rounding being used is Banker's Rounding, so numbers ending in .5 will not always "behave" as expected (since the rounding will be toward the even whole number). I also highly dislike their use of "truncated" in the last paragraph... nothing is truncated... both numbers are Banker's Rounded to whole numbers where the Mod function then performs normally.

Rick

.



Relevant Pages

  • Re: Decimal Display
    ... Rick Rothstein wrote: and number containing fractions BEFORE it performs the Mod operations. ... The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. ... Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Variant containing a Long, regardless of whether or not result is a whole number. ...
    (microsoft.public.vb.general.discussion)
  • Re: VHDL real numbers
    ... The rule rounding has to do with the bottom bit of the integer portion. ... If the remainder is greater than 0.5, round up ... This is the functionality of "round nearest", which should be the default rounding style for all floating point numbers. ...
    (comp.lang.vhdl)
  • Re: Calculating Moon Phases
    ... The modulus, or remainder, operator divides number1 by number2 (rounding ... floating-point numbers to integers) and returns only the remainder as result. ... Note the comment about the rounding so essentially, ...
    (microsoft.public.vb.general.discussion)
  • Re: Decimal Display
    ... Rick Rothstein wrote: and number containing fractions BEFORE it performs the Mod operations. ... The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. ... Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Variant containing a Long, regardless of whether or not result is a whole number. ...
    (microsoft.public.vb.general.discussion)
  • Re: Decimal Display
    ... Rick Rothstein wrote: and number containing fractions BEFORE it performs the Mod operations. ... The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. ... Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Variant containing a Long, regardless of whether or not result is a whole number. ...
    (microsoft.public.vb.general.discussion)