Funzioni di conversione del numero di VBScript

Sintassi

Variable_name = Conversion_function_name(expression)

Le funzioni numeriche ci aiutano a convertire un dato numero da un sottotipo di dati a un altro sottotipo di dati.

Suor n Descrizione della funzione
1

CDbl

Una funzione, che converte un dato numero di qualsiasi sottotipo di variante in doppio

2

CInt

Una funzione, che converte un dato numero di qualsiasi sottotipo variante in Integer

3

CLng

Una funzione, che converte un dato numero di qualsiasi sottotipo variante in Long

4

CSng

Una funzione, che converte un dato numero di qualsiasi sottotipo variante in Single

5

Hex

Una funzione, che converte un dato numero di qualsiasi sottotipo variante in esadecimale

Esempio

Prova il seguente esempio per comprendere tutte le funzioni di conversione dei numeri disponibili 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>

Quando viene eseguito, lo script precedente produrrĂ  il seguente 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