VBScript Number Conversion Functions


Advertisements


Syntax

Variable_name = Conversion_function_name(expression)

The following table shows the possible number conversion functions in VBScript. Number Functions help the developers to handle numbers in an efficient way and also helps them to convert the given input to their sub types.

Function Description
CDbl A Function, which converts a given number of any variant subtype to double
CInt A Function, which converts a given number of any variant subtype to Integer
CLng A Function, which converts a given number of any variant subtype to Long
CSng A Function, which converts a given number of any variant subtype to Single
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, following is the 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