VBScript 中的数学函数
语法
variablename = Mathematical_function_Name(Expression)
数学函数帮助我们评估给定输入数字的数学和三角函数。
Sr.No | 功能与描述 |
---|---|
1 | Int 一个函数,返回给定数字的整数部分 |
2 | Fix 一个函数,返回给定数字的整数部分 |
3 | Log 一个函数,返回给定数字的自然对数。 不允许使用负数 |
4 | Oct 一个函数,返回给定百分比的八进制值 |
5 | Hex 一个函数,返回给定数字的十六进制值 |
6 | Rnd 一个函数,返回 0 到 1 之间的随机数 |
7 | Sgn 一个函数,返回与指定数字的符号对应的数字 |
8 | Sqr 一个函数,返回给定数字的平方根。 不允许使用负数 |
9 | Abs 一个函数,返回给定数字的绝对值 |
10 | Exp 一个函数,返回 e 增加到指定数字后的值 |
11 | Sin 一个函数,返回给定数字的正弦值 |
12 | Cos 一个函数,返回给定数字的余弦值 |
13 | Tan 一个函数,返回给定数字的 tan 值 |
示例
尝试以下示例来了解 VBScript 中可用的所有内置数学函数。
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim num1 : num1 = -645.998651 Dim num2 : num2 = 210 document.write("int Result of num1 is : " & int(num1))& "<br/>" document.write("int Result of num2 is : " & int(num2))& "<br/>" document.write("Fix Result of num1 is : " & Fix(num1))& "<br/>" document.write("Fix Result of num2 is : " & Fix(num2))& "<br/>" document.write("Log Result of num2 is : " & Log(num2))& "<br/>" document.write("Oct Result of num1 is : " & Oct(num1))& "<br/>" document.write("Oct Result of num2 is : " & Oct(num2))& "<br/>" document.write("Hex Result of num1 is : " & Hex(num1))& "<br/>" document.write("Hex Result of num2 is : " & Hex(num2))& "<br/>" document.write("Rnd Result of num1 is : " & Rnd(num1))& "<br/>" document.write("Rnd Result of num2 is : " & Rnd(num2))& "<br/>" document.write("Sgn Result of num1 is : " & Sgn(num1))& "<br/>" document.write("Sgn Result of num2 is : " & Sgn(num2))& "<br/>" document.write("Sqr Result of num2 is : " & Sqr(num2))& "<br/>" document.write("Abs Result of num1 is : " & Abs(num1))& "<br/>" document.write("Abs Result of num2 is : " & Abs(num2))& "<br/>" document.write("Exp Result of num1 is : " & Exp(num1))& "<br/>" document.write("Exp Result of num2 is : " & Exp(num2))& "<br/>" document.write("Sin Result of num1 is : " & Sin(num1))& "<br/>" document.write("Sin Result of num2 is : " & Sin(num2))& "<br/>" document.write("Cos Result of num1 is : " & Cos(num1))& "<br/>" document.write("Cos Result of num2 is : " & Cos(num2))& "<br/>" document.write("Tan Result of num1 is : " & Tan(num1))& "<br/>" document.write("Tan Result of num2 is : " & Tan(num2))& "<br/>" </script> </body> </html>
执行上述脚本后,输出如下 −
int Result of num1 is : -646 int Result of num2 is : 210 Fix Result of num1 is : -645 Fix Result of num2 is : 210 Log Result of num2 is : 5.34710753071747 Oct Result of num1 is : 37777776572 Oct Result of num2 is : 322 Hex Result of num1 is : FFFFFD7A Hex Result of num2 is : D2 Rnd Result of num1 is : 0.5130115 Rnd Result of num2 is : 0.5615935 Sgn Result of num1 is : -1 Sgn Result of num2 is : 1 Sqr Result of num2 is : 14.4913767461894 Abs Result of num1 is : 645.998651 Abs Result of num2 is : 210 Exp Result of num1 is : 2.79479883633128E-281 Exp Result of num2 is : 1.59162664037792E+91 Sin Result of num1 is : 0.920530264916375 Sin Result of num2 is : 0.467718518342759 Cos Result of num1 is : 0.390671257418547 Cos Result of num2 is : -0.883877473182372 Tan Result of num1 is : 2.35627845006822 Tan Result of num2 is : -0.529166691689464