VBScript 数字转换函数
语法
Variable_name = Conversion_function_name(expression)
数字函数帮助我们将给定数字从一种数据子类型转换为另一种数据子类型。
Sr.No | 功能与描述 |
---|---|
1 | CDbl 一个函数,它将给定数量的任何变体子类型转换为双精度 |
2 | CInt 一个函数,它将给定数量的任何变体子类型转换为整数 |
3 | CLng 一个函数,它将给定数量的任何变体子类型转换为 Long |
4 | CSng 一个函数,它将给定数量的任何变体子类型转换为 Single |
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