Convert double to byte[] array

前端 未结 5 1469
灰色年华
灰色年华 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条回答
  •  醉梦人生
    2020-12-22 10:47

    This is what I got based on your inputs and it serves my purpose. Thanks for helping out!

    static int formatDoubleToAscii(double d, int bytesToUse, int minPrecision, byte in[], int startPos) {
    
            int d1 = (int)(d * Math.pow(10, minPrecision));
    
            String t = String.format("%0"+bytesToUse+"d", d1).toString();
            System.out.println("d1 = "+ d1 + " t="+ t + " t.length=" + t.length());
    
            for(int i=0 ; i

提交回复
热议问题