VBScript 数字转换函数



语法

Variable_name = Conversion_function_name(expression)

数字函数帮助我们将给定数字从一个数据子类型转换为另一个数据子类型。

序号 函数和说明
1

CDbl

一个函数,将给定任何变体子类型的数字转换为双精度

2

CInt

一个函数,将给定任何变体子类型的数字转换为整型

3

CLng

一个函数,将给定任何变体子类型的数字转换为长整型

4

CSng

一个函数,将给定任何变体子类型的数字转换为单精度

5

Hex

一个函数,将给定任何变体子类型的数字转换为十六进制

示例

尝试以下示例以了解 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>

执行时,上述脚本将产生以下输出 −

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
广告