Mathematical Functions in VBScript


Advertisements

Syntax

variablename = Mathematical_function_Name(Expression) 

Mathematical Functions help us to evaluate the mathematical and trigonometrical functions of a given input number.

Sr.No Function & Description
1

Int

A Function, which returns the integer part of the given number

2

Fix

A Function, which returns the integer part of the given number

3

Log

A Function, which returns the natural logarithm of the given number. Negative numbers disallowed

4

Oct

A Function, which returns the Octal value of the given percentage

5

Hex

A Function, which returns the Hexadecimal value of the given number

6

Rnd

A Function, which returns a random number between 0 and 1

7

Sgn

A Function, which returns a number corresponding to the sign of the specified number

8

Sqr

A Function, which returns the square root of the given number. Negative numbers disallowed

9

Abs

A Function, which returns the absolute value of the given number

10

Exp

A Function, which returns the value of e raised to the specified number

11

Sin

A Function, which returns sine value of the given number

12

Cos

A Function, which returns cosine value of the given number

13

Tan

A Function, which returns tan value of the given number

Example

Try the following example to understand all the inbuilt Mathematical Functions available in 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>

When executed the above script, following is the output −

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
vbscript_numbers.htm
Advertisements