Fonctions de conversion de nombres VBScript

Syntaxe

Variable_name = Conversion_function_name(expression)

Les fonctions numériques nous aident à convertir un nombre donné d'un sous-type de données à un autre sous-type de données.

Sr.Non Description de la fonction
1

CDbl

Une fonction, qui convertit un nombre donné de n'importe quel sous-type de variante en double

2

CInt

Une fonction, qui convertit un nombre donné de n'importe quel sous-type de variante en Integer

3

CLng

Une fonction, qui convertit un nombre donné de n'importe quel sous-type de variant en Long

4

CSng

Une fonction, qui convertit un nombre donné de n'importe quel sous-type de variante en Single

5

Hex

Une fonction, qui convertit un nombre donné de n'importe quel sous-type de variante en hexadécimal

Exemple

Essayez l'exemple suivant pour comprendre toutes les fonctions de conversion de nombres disponibles dans 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>

Une fois exécuté, le script ci-dessus produira la sortie suivante -

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