VBScript 中的算术运算符
下表显示了VBScript语言支持的所有算术运算符。 假设变量 A 为 5,变量 B 为 10,则 −
| 运算符 | 描述 | 示例 |
|---|---|---|
| + | 添加两个操作数 | A + B 将给出 15 |
| - | 从第一个操作数中减去第二个操作数 | A - B 将给出 -5 |
| * | 将两个操作数相乘 | A * B 将给出 50 |
| / | 分子除以分子 | B / A 将给出 2 |
| % | 模数运算符和整数除法后的余数 | B MOD A 将给出 0 |
| ^ | 求幂运算符 | B ^ A 将给出 100000 |
示例
尝试以下示例来了解 VBScript 中可用的所有算术运算符 −
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim a : a = 5
Dim b : b = 10
Dim c
c = a+b
Document.write ("Addition Result is " &c)
Document.write ("<br></br>") 'Inserting a Line Break for readability
c = a-b
Document.write ("Subtraction Result is " &c)
Document.write ("<br></br>") 'Inserting a Line Break for readability
c = a*b
Document.write ("Multiplication Result is " &c)
Document.write ("<br></br>")
c = b/a
Document.write ("Division Result is " &c)
Document.write ("<br></br>")
c = b MOD a
Document.write ("Modulus Result is " &c)
Document.write ("<br></br>")
c = b^a
Document.write ("Exponentiation Result is " &c)
Document.write ("<br></br>")
</script>
</body>
</html>
当您将其另存为 .html 并在 Internet Explorer 中执行时,上述脚本将产生以下结果 −
Addition Result is 15 Subtraction Result is -5 Multiplication Result is 50 Division Result is 2 Modulus Result is 0 Exponentiation Result is 100000

vbscript_operators.html