Convert double to byte[] array

前端 未结 5 1540
灰色年华
灰色年华 2020-12-22 10:16

How can I convert double to byte array in Java? I looked at many other posts, but couldn\'t figure out the right way.

Input = 65.43 
byte[] size = 6
precisi         


        
5条回答
  •  -上瘾入骨i
    2020-12-22 10:50

    double doubleValue = 10.42123;
    DecimalFormat df = new DecimalFormat("#.##");
    String newDouble = df.format(doubleValue);
    byte[] byteArray = (newDouble.replace(",", "")).getBytes();
    
    for (byte b : byteArray) {
        System.out.println((char)b+"");
    }
    

提交回复
热议问题