Java Double Convert to double2sortableStr(double val)

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

Description

doublesortable Str

License

Apache License

Declaration

public static String double2sortableStr(double val) 

Method Source Code

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

public class Main {
    public static String double2sortableStr(double val) {
        long f = Double.doubleToRawLongBits(val);
        if (f < 0)
            f ^= 0x7fffffffffffffffL;/*from w ww . java2s  .  c  o  m*/
        return long2sortableStr(f);
    }

    public static String double2sortableStr(String val) {
        return double2sortableStr(Double.parseDouble(val));
    }

    public static String long2sortableStr(long val) {
        char[] arr = new char[5];
        long2sortableStr(val, arr, 0);
        return new String(arr, 0, 5);
    }

    public static String long2sortableStr(String val) {
        return long2sortableStr(Long.parseLong(val));
    }

    public static int long2sortableStr(long val, char[] out, int offset) {
        val += Long.MIN_VALUE;
        out[offset++] = (char) (val >>> 60);
        out[offset++] = (char) (val >>> 45 & 0x7fff);
        out[offset++] = (char) (val >>> 30 & 0x7fff);
        out[offset++] = (char) (val >>> 15 & 0x7fff);
        out[offset] = (char) (val & 0x7fff);
        return 5;
    }
}

Related

  1. double2fixed(double value)
  2. double2Float(double[] v)
  3. double2int(final double d)
  4. double2long(double value)
  5. double2short(double d)