Classe Java Float méthode toHexString() avec exemple
Float class toHexString() method
- méthode toHexString() est disponible dans le package java.lang.
- méthode toHexString() est utilisé pour représenter une chaîne hexadécimale du paramètre donné [valeur] de type virgule flottante simple précision.
- méthode toHexString() est une méthode statique, elle est également accessible avec le nom de la classe et si nous essayons d'accéder à la méthode avec l'objet de la classe, nous n'obtiendrons pas non plus d'erreur.
- méthode toHexString() ne lève pas d'exception au moment de la conversion de float en chaîne hexadécimale.
Syntaxe :
public static String toHexString (float value);
Paramètre(s) :
- valeur flottante :représente la valeur flottante à convertir.
Valeur renvoyée :
Le type de retour de cette méthode est String, elle renvoie la chaîne hexadécimale du paramètre donné qui représente la valeur flottante.
Exemple :
// Java program to demonstrate the example // of toHexString(float value) method of Float class public class ToHexStringOfFloatClass { public static void main(String[] args) { // Variables initialization float f1 = 10.0f; float f2 = 20.0f; float f3 = 30.0f; float f4 = Float.MAX_VALUE; float f5 = Float.MIN_VALUE; // Float instance creation Float value = new Float(f1); // It represents hexadecimal string of the given // float type f2 argument String s = value.toHexString(f2); // Display Hexadecimal String Representation System.out.println("value.toHexString(f2): " + s); // It represents hexadecimal string of the given // float type f3 argument s = value.toHexString(f3); // Display Hexadecimal String Representation System.out.println("value.toHexString(f3): " + s); // It represents hexadecimal string of the given // float type f4 argument s = value.toHexString(f4); // Display Hexadecimal String Representation System.out.println("value.toHexString(f4): " + s); // It represents hexadecimal string of the given // float type f5 argument s = value.toHexString(f5); // Display Hexadecimal String Representation System.out.println("value.toHexString(f5): " + s); } }
Sortie
value.toHexString(f2): 0x1.4p4 value.toHexString(f3): 0x1.ep4 value.toHexString(f4): 0x1.fffffep127 value.toHexString(f5): 0x0.000002p-126