Re: Decimal Display
- From: dpb <none@xxxxxxx>
- Date: Fri, 14 Sep 2007 18:38:37 -0500
Rick Rothstein (MVP - VB) wrote:
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.
Any fractional part of the _RESULT_ is truncated. That is as opposed to rounding the result of the division after the dividend and divisor are previously rounded. Other than the omission of the rounding mode (not a trivial omission, granted), the description is pretty much spot on I think.
???
The Mod operator returns the "whole number" remainder after division... there is never a fractional result (the Banker's Rounding before performing the Mod operation insures that). The Mod operation is like how you first learned division (before you learned about decimal places)... 19 divided by 5 is 3 with a remainder of 4... the remainder of 4 is what the Mod function returns.
My bad...wasn't thinking straight. Was thinking of the other way 'round, the why of which I can't explain... :(
--
.
- References:
- Decimal Display
- From: Pop`
- Re: Decimal Display
- From: DanS
- Re: Decimal Display
- From: Rick Rothstein \(MVP - VB\)
- Re: Decimal Display
- From: Robert Morley
- Re: Decimal Display
- From: Ken Halter
- Re: Decimal Display
- From: Rick Rothstein \(MVP - VB\)
- Re: Decimal Display
- From: dpb
- Re: Decimal Display
- From: Rick Rothstein \(MVP - VB\)
- Decimal Display
- Prev by Date: Re: Decimal Display
- Next by Date: Re: VB5 forcing data to disk
- Previous by thread: Re: Decimal Display
- Next by thread: Re: Decimal Display
- Index(es):
Relevant Pages
|