Java Utililty Methods Double to

List of utility methods to do Double to

Description

The list of methods to do Double to are organized into topic(s).

Method

StringdoubleToFractionStr(final Double d)
Converts a double to a string fraction, i.e.
boolean negative = false;
Double v = d;
if (v < 0) {
    negative = true;
    v = -v;
int w = (int) ((v - Math.floor(v)) * FACTOR);
int gcd = gcd(w, FACTOR);
...
StringdoubleToHashString(double value)
double To Hash String
StringBuilder sb = new StringBuilder(16);
long bits = Double.doubleToLongBits(value);
for (int i = 7; i >= 0; i--) {
    int byteValue = (int) ((bits >>> (8 * i)) & 0xff);
    int high = ((byteValue >> 4) & 0xf);
    int low = (byteValue & 0xf);
    sb.append(HEX_CHARACTERS[high]);
    sb.append(HEX_CHARACTERS[low]);
...
StringdoubleToHexString(double val)
double To Hex String
long reversed = Long.reverseBytes(Double.doubleToLongBits(val));
String res = Long.toHexString(reversed);
res = "0000000000000000".substring(res.length()) + res;
return res;
StringdoubleToI18nString(double d)
double To In String
return doubleToI18nString(d, false);
intdoubleToIndex(final double x)
double To Index
final long j = Double.doubleToRawLongBits(x);
final long k = j >>> (64 - BITS);
assert k <= Integer.MAX_VALUE;
return (int) k;
byte[]doubleToLex(double v)
Converts a regular java double to a lexicographical sortable double
long l = Double.doubleToLongBits(v);
if (Double.isNaN(v)) { 
} else if (v >= 0) {
    l ^= c64;
} else {
    l ^= 0xFFFFFFFFFFFFFFFFL;
return longBytes(l, new byte[8], 0);
...
StringdoubleToPercent(double value, int precision)
Convert a double value to percentage
long tempValue = Math.round(value * (Math.pow(10, (precision + 2))));
String percentValue = null;
if (precision == 0)
    percentValue = String.valueOf((double) tempValue);
else
    percentValue = String.valueOf(((double) tempValue) / (Math.pow(10, precision)));
percentValue += '%';
return percentValue;
...
long[]doubleToRational(double number)
double To Rational
if ((number == 0.0d) || Double.isNaN(number)) {
    throw new IllegalArgumentException(number + " cannot be represented as a rational number");
long bits = Double.doubleToLongBits(number);
long sign = bits >>> 63;
long exponent = ((bits >>> 52) ^ (sign << 11)) - 1023;
long fraction = bits << 12; 
long a = 1L;
...
byte[]doubleToRegisters(double d)
Converts a double value to a byte[8].
return longToRegisters(Double.doubleToLongBits(d));
intdoubleToScale(double val)
Converts a double to a 24 bit register value.
int temp = (int) (val * (double) 0x400000);
if (temp > 0x7fffff) {
    temp = 0x7fffff;
if (temp < -0x800000) {
    temp = -0x800000;
return temp;
...