VBScript Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.01

Numeric Operations

Part:   1  2  

VB Script Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Data Types and Literals

Variables

Logic Operations

String Operations

Conditional Statements

Arrays

Loop Statements

Functions and Subroutines

Built-in Functions

Variable Inspection

... Table of Contents

(Continued from previous part...)

Double Floating Number Operations

Double floating number operations are mathematical operations that:

  • Operates on two double floating number operands. If an operand is not a double floating number, it will be converted into a double floating number.
  • Produces a double floating number by applying the mathematical operation specified by the operator.

There are 5 double floating number 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 (/): First operand divided by the second operand.
  • Exponentiation (^) - First operand raised to the power of the second operand.

To show you how double floating number operations work, I wrote the following script, floating_operation.html:

<html>
<body>
<!-- float_operation.html
   Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
   document.writeln(3.333e200 + 0.111e200)
   document.writeln(1.0e0 - 1.0e20)
   document.writeln(11.0 * 1.0e20)
   document.writeln(20.0e20 / 3.0e0)
   document.writeln(3 ^ 40)
</script>
</pre>
</body>
</html>

Here is the output:

3.444E+200
-1E+20
1.1E+21
6.66666666666667E+20
1.21576654590569E+19

No surprises in the output.

Numeric Operations on Other Data Types

VB does support numeric operations on currency data type. But I don't know exactly how they work.

There seems to be no numeric operations available on date, Boolean, and string data types.

Conclusions

  • VB supports 6 numeric operations on integers.
  • The whole number division operator sign is (\).
  • VB supports 5 numeric operations on floating numbers.

Part:   1  2  

Dr. Herong Yang, updated in 2006
VBScript Tutorials - Herong's Tutorial Notes - Numeric Operations