Home » Java programming language

Java Double class toHexString() method with example

Double class toHexString() method: Here, we are going to learn about the toHexString() method of Double class with its syntax and example.
Submitted by Preeti Jain, on September 23, 2019

Double class toHexString() method

  • toHexString() method is available in java.lang package.
  • toHexString() method is used to get the hexadecimal string representation of the given parameter [value] of double floating-point type.
  • toHexString() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • toHexString() method does not throw an exception at the time of conversion from double to Hexadecimal string.

Syntax:

    public static String toHexString(double value);

Parameter(s):

  • double value – represents the double value to be converted.

Return value:

The return type of this method is string, it returns the hexadecimal string of the given parameter that represent the double value.

Example:

// Java program to demonstrate the example 
// of toHexString(double value) method of Double class

public class ToHexStringOfDoubleClass {
    public static void main(String[] args) {
        // Variables initialization
        double d1 = 10.0;
        double d2 = 20.0;
        double d3 = 30.0;
        double d4 = Double.MAX_VALUE;
        double d5 = Double.MIN_VALUE;

        // Double instance creation
        Double value = new Double(d1);

        // It represents hexadecimal string of the given
        // double type d2 argument
        String s = value.toHexString(d2);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d2): " + s);

        // It represents hexadecimal string of the given
        // double type d3 argument
        s = value.toHexString(d3);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d3): " + s);

        // It represents hexadecimal string of the given
        // double type d4 argument
        s = value.toHexString(d4);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d4): " + s);

        // It represents hexadecimal string of the given
        // double type d5 argument
        s = value.toHexString(d5);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d5): " + s);
    }
}

Output

value.toHexString(d2): 0x1.4p4
value.toHexString(d3): 0x1.ep4
value.toHexString(d4): 0x1.fffffffffffffp1023
value.toHexString(d5): 0x0.0000000000001p-1022





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.