Vbscript-number-conversion-functions

提供:Dev Guides
移動先:案内検索

VBScriptの数値変換関数

構文

Variable_name = Conversion_function_name(expression)

数値関数は、特定の数値をあるデータサブタイプから別のデータサブタイプに変換するのに役立ちます。

Sr.No Function & Description
1

CDbl

任意のバリアントサブタイプの指定された数をdoubleに変換する関数

2

CInt

任意のバリアントサブタイプの指定された数を整数に変換する関数

3

CLng

任意のバリアントサブタイプの指定された数をLongに変換する関数

4

CSng

任意のバリアントサブタイプの指定された数をシングルに変換する関数

5

Hex

任意のバリアントサブタイプの指定された数を16進数に変換する関数

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