Mathematical Operations in UFT

In UFT, we can perform various mathematical operations like finding square root, random numbers, absolute value, Trigonometric functions etc. In below example, we have used all mathematical functions.
 
'Rounding the numbers

'To round the number to 2 digits.......Answer is 422.43
Msgbox "Rounding the number 422.432 is " & round(422.432,2)  

'Getting the integer portion of a number
'If the number is negative, int  will return smallest possible integer value while fix will return largest possible integer value 
'For positive numbers, both int and fix will get the nearest integer number

Msgbox "Int(-9.4) is " & Int (-9.4) 
Msgbox "Fix(-9.4) is " & Fix(-9.4) 
Msgbox "Int(9.4) is " & Int (9.4) 
Msgbox "Fix(9.4) is " & Fix(9.4) 

'gets the random number.....It will print any random number
Msgbox "Random number -> " & Rnd()

'We must use Randomize function before Rnd to get different values
'To get the random numbers between 2 integers
max=999
min=1
Randomize
'This will print any random number between 1 and 999
Msgbox "Random number between 1 and 999 is -> " & (Int((max-min+1)*Rnd+min))

'To find the absolute value ......Answer is 1422
Msgbox "Absolute value of -1422 is " & Abs(-1422) 

'Sign of a number......Answer is -1
Msgbox "Sign of number -322 is " & Sgn(-322)  

'Trigonometric calculations in UFT
Msgbox "Sin(180) is -> " & Sin(180) 
Msgbox "Tan(90) is -> " & Tan(90)
Msgbox "Atn(45) is -> " & Atn(45) 
Msgbox "Cos(360) is -> " & Cos(360)


'To find the square root of the number...........Answer is 11
Msgbox "Square root of 121 is " & Sqr (121) 

'Calculates natural logarithm to the base e
Msgbox "log(10) to the base e is -> " & Log(10)

'Exponentiation 
Msgbox "Exponentiation e^2 is -> " & Exp(2)     

Web development and Automation testing

solutions delivered!!