Convert double value to byte array. - Java java.lang

Java examples for java.lang:byte Array Convert

Description

Convert double value to byte array.

Demo Code


//package com.java2s;
import javax.annotation.Nonnull;

import java.nio.ByteBuffer;

public class Main {
    public static void main(String[] argv) throws Exception {
        double value = 2.45678;
        System.out.println(java.util.Arrays.toString(doubleToBytes(value)));
    }/*from  w w  w . ja  va  2 s. c o  m*/

    /**
     * Convert double value to byte array.
     */
    @Nonnull
    public static byte[] doubleToBytes(double value) {
        return ByteBuffer.allocate(Double.BYTES).putDouble(value).array();
    }
}

Related Tutorials