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

double[][]doubleTo2DArray(double[] array)
Convert a single dimensional double array to a 2D array, where the first dimension matches that of the original array and second is always 0 (with our convention for first index being time and second variable number, this means we have a 2D array where the original array becomes the first variable).
double[][] twoDArray = new double[array.length][1];
for (int i = 0; i < array.length; i++) {
    twoDArray[i][0] = array[i];
return twoDArray;
TdoubleToBasicType(double d, Class clazz)
double To Basic Type
if (clazz.equals(Boolean.class))
    return (T) Boolean.valueOf(doubleToBoolean(d));
if (clazz.equals(Byte.class))
    return (T) doubleToByte(d);
if (clazz.equals(Character.class))
    return (T) doubleToCharacter(d);
if (clazz.equals(Short.class))
    return (T) doubleToShort(d);
...
StringdoubleToBinaryString(double value)
double To Binary String
return (value < 0 ? "1" : "0") + Long.toBinaryString(Double.doubleToLongBits(Math.abs(value)));
StringdoubleToBits(double in, double min, double max, int numBits, int splits)
Turns a double into a bit string (0s and 1s).
if (in > max) {
    in = max;
if (in < min) {
    in = min;
double sdist = (max - min) / ((double) splits - 1);
double dist = in - min;
...
StringdoubleToBits(double num)
double To Bits
return Long.toBinaryString(Double.doubleToLongBits(num));
chardoubleToChar(double d, char defaultValue)
double To Char
if (d >= Character.MIN_VALUE && d <= Character.MAX_VALUE) {
    return (char) d;
return defaultValue;
Double[]doubleToDoubleArray(double... a)
Converts a double[] to a Double[] (auto-boxing doesn't work for arrays...)
Double[] aDouble = new Double[a.length];
for (int i = 0; i < a.length; i++) {
    aDouble[i] = a[i];
return aDouble;
float[]doubleToFloatArray(double[] dArray)
double To Float Array
float[] fArray = new float[dArray.length];
for (int i = 0; i < dArray.length; i++) {
    fArray[i] = (float) dArray[i];
return fArray;
float[]doubleToFloatArray(double[] doubles)
Convert a double array into a float array
float[] floats = new float[doubles.length];
for (int i = 0; i < doubles.length; i++) {
    floats[i] = (float) doubles[i];
return floats;
float[][]doubleToFloatMatrix(double[][] matrix)
double To Float Matrix
float retMatrix[][] = new float[matrix.length][matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++) {
        retMatrix[i][j] = (float) matrix[i][j];
return retMatrix;