Viacheslav Eremin | Visual Basic Language Reference | Mod Operator
Có thể bạn quan tâm
Divides two numbers and returns only the remainder.
number1 Mod number2Parts
number1 Required. Any numeric expression. number2 Required. Any numeric expression.Result
The result is the remainder left after division is performed on number1 and number2.
Supported Types
Byte, Short, Integer, Long, Single, Double, Decimal
Remarks
The Mod operator divides number1 by number2 and returns only the remainder as result. For example, in the following expression, A (result) equals 2.
A = 8 Mod 3If number1 or number2 are floating-point values, then division is carried out and the floating-point remainder is returned. Thedata type of the result is the same as that of the data type with the greatest range. The order of range, from least to greatest range, is Byte, Short, Integer, Long, Single, Double, and Decimal.
If any expression is stated as Nothing, or Empty, it is treated as zero. If division by zero occurs, the Mod operation returns NaN (Not a Number).
A Mod B is the equivalent of A - Int(A / B) * B + CLng(Math.Sign(A) <> Math.Sign(B)) * B
Example
This example uses the Mod operator to divide two numbers and return only the remainder. If either number is a floating-point number, the result is a floating-point number representing the remainder.
Dim myResult As Double myResult = 10 Mod 5 ' Returns 0. myResult = 10 Mod 3 ' Returns 1. myResult = 12 Mod 4.3 ' Returns 3.4. myResult = 12.6 Mod 5 ' Returns 2.6. myResult = 47.9 Mod 9.35 ' Returns 1.15.See Also
Arithmetic Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | Arithmetic Operators
Send feedback to Microsoft
© 2001 Microsoft Corporation. All rights reserved.
Từ khóa » Visual Basic Mod Operator
-
Mod Operator - Visual Basic | Microsoft Docs
-
Mod Operator - Microsoft Docs
-
Can Someone Explain The 'mod' Operator In In The Simplest ...
-
VB.NET Mod: Modulo Division Example - Dot Net Perls
-
Mod Operator - Microsoft Visual Basic Constants Documentation
-
Mod Operator In Excel VBA (In Easy Steps)
-
Mod - Operator Of Language VBScript - Promotic
-
How To Use MOD In VBA - Excel Champs
-
How To Use VBA Mod Operator (9 Examples) - ExcelDemy
-
Mod Operator - ADM Help Centers
-
Mod Operator - VB .NET Language In A Nutshell [Book]
-
MS Excel: How To Use The MOD Function (VBA) - TechOnTheNet