|
Numeric Operations
Part:
1
2
This chapter describes:
- Long Integer Operations
- Double Floating Number Operations
- Numeric Operations on Other Data Types
Notes and samples in this chapter are based Visual Basic 6.0.
Long Integer Operations
Long integer operations are numeric operations that:
- Operates on two long integer operands. If an operand is not a long integer,
it will be converted into a long integer.
- Produces a long integer by applying the mathematical operation specified by the operator.
There are 6 long integer operations supported in VB:
- Addition (+): Mathematical sum of both operands.
- Subtraction (-): First operand subtracted by the second operand.
- Multiplication (*): First operand multiplied by the second operand.
- Division (\) - Whole number division: First operand divided by the second operand with decimal fraction part removed.
- Remainder (Mod) - Remainder division: The remaining value of the whole number division.
- Exponentiation (^) - First operand raised to the power of the second operand.
To show you how long integer operations work, I wrote the following script, integer_operation.html:
<html>
<body>
<!-- integer_operation.html
Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
document.writeln(1 + 1)
document.writeln(0 - 3)
document.writeln(9 * 9)
document.writeln(20 \ 3)
document.writeln(20 Mod 3)
document.writeln(3 ^ 4)
</script>
</pre>
</body>
</html>
Here is the output:
2
-3
81
6
2
81
No surprises in the output. But the whole number division operator uses a un-usual operator sign (\)
comparing to other programming languages.
(Continued on next part...)
Part:
1
2
|