Re: Decimal Display
- From: "Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Fri, 14 Sep 2007 17:33:33 -0400
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
.
- Follow-Ups:
- Re: Decimal Display
- From: dpb
- Re: Decimal Display
- 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
- Decimal Display
- Prev by Date: Re: Decimal Display
- Next by Date: Re: Decimal Display
- Previous by thread: Re: Decimal Display
- Next by thread: Re: Decimal Display
- Index(es):
Relevant Pages
|