VBScript Number Conversion Functions


Advertisements

Syntax

Variable_name = Conversion_function_name(expression)

Number functions help us to convert a given number from one data subtype to another data subtype.

Sr.No Function & Description
1

CDbl

A Function, which converts a given number of any variant subtype to double

2

CInt

A Function, which converts a given number of any variant subtype to Integer

3

CLng

A Function, which converts a given number of any variant subtype to Long

4

CSng

A Function, which converts a given number of any variant subtype to Single

5

Hex

A Function, which converts a given number of any variant subtype to Hexadecimal

Example

Try the following example to understand all the Number Conversion Functions available in VBScript.

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         x = 123
         y = 123.882
         document.write("x value after converting to double - " & CDbl(x) & "<br />")
         
         document.write("y value after converting to double - " & CDbl(y) & "<br />")
         
         document.write("x value after converting to Int -" & CInt(x) & "<br />")
         
         document.write("y value after converting to Int -" & CInt(y) & "<br />")
         
         document.write("x value after converting to Long -" & CLng(x) & "<br />")
         
         document.write("y value after converting to Long -" & CLng(y) & "<br />") 
         
         document.write("x value after converting to Single -" & CSng(x) & "<br />")
         
         document.write("y value after converting to Single -" & CSng(y) & "<br />") 
         
         document.write("x value after converting to Hex -" & Hex(x) & "<br />")
         
         document.write("y value after converting to Hex -" & Hex(y) & "<br />") 
      </script>
   </body>
</html>

When executed, the above script will produce the following output −

x value after converting to double - 123
y value after converting to double - 123.882
x value after converting to Int -123
y value after converting to Int -124
x value after converting to Long -123
y value after converting to Long -124
x value after converting to Single -123
y value after converting to Single -123.882
x value after converting to Hex -7B
y value after converting to Hex -7C
vbscript_numbers.htm
Advertisements