Java Double Convert to convertDoubleIntoHexadecimalString(double value, int precision)

Here you can find the source of convertDoubleIntoHexadecimalString(double value, int precision)

Description

convert Double Into Hexadecimal String

License

Apache License

Declaration

public static String convertDoubleIntoHexadecimalString(double value, int precision) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String convertDoubleIntoHexadecimalString(double value, int precision) {

        double fractionValue = value % 1;
        int intValue = (int) (value - fractionValue);

        String str = Integer.toHexString(intValue);

        if (fractionValue != 0) {

            str += ".";
            StringBuilder dec = new StringBuilder();

            while ((fractionValue *= 16) != 0 && dec.length() < precision) {

                double temp = fractionValue % 1;
                intValue = (int) (fractionValue - temp);
                fractionValue = temp;//from  www. j av a  2  s.c  o  m

                dec.append(Integer.toHexString(intValue));
            }

            str += dec;
        }

        return str;
    }
}

Related

  1. convertDouble(String str, double defaults)
  2. convertDouble2double(final Double[] pArray)
  3. convertDoubleArrayToString(double[] value, String separator)
  4. convertDoubleConsonant(byte[] b)
  5. convertDoubleFromBytes(final byte[] bytes)
  6. convertDoubleList(Double[] list)
  7. convertDoubleMatrixToFloat(double[][] input, int dimRows, int dimColoumns)
  8. convertDoubleNumberFromSciNotation(String numberInScientificNotation)
  9. convertDoubles(Double[] doubles)