Java Double to Long doubleToLongBits(double val)

Here you can find the source of doubleToLongBits(double val)

Description

double To Long Bits

License

Apache License

Declaration

private static long doubleToLongBits(double val) 

Method Source Code

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

public class Main {
    private static long doubleToLongBits(double val) {

        String dbl = String.valueOf(val);
        int decimpoints = dbl.indexOf(".") > -1 ? dbl.split("\\.")[1].length() : 1;
        long factor = (long) Math.pow(10, decimpoints);
        val = val * factor;

        return Math.round(val);
    }//from  w  w  w . ja  v a2s  . co m

    public static double round(double amount) {
        double tmp1 = amount;
        long factor = (long) Math.pow(10, 2);
        tmp1 = tmp1 * factor;
        long tmp = Math.round(Math.abs(tmp1));
        amount = ((amount < 0 && tmp != 0) ? -1 : 1) * ((double) tmp / factor);
        String[] strArr = String.valueOf(amount).split("\\.");
        //
        // amount = Double.parseDouble(strArr[0] + "."
        // + (strArr.length > 1 ? strArr[1].substring(0, 2) : "00"));
        return amount;
    }
}

Related

  1. doubleToLong(double d)
  2. doubleToLong(double[] values)
  3. doubleToLong(final double d)
  4. DoubleToLong_With_Little_Endian(double dd)
  5. doubleToLongArray(final double value)
  6. doubleToLongBits(double value)
  7. doubleToLongBits(final double d)
  8. doubleToLongBits(final double v)
  9. doubleToRawLongBits(double d)