How to convert array of floats to array of doubles in Java?

后端 未结 3 1923
深忆病人
深忆病人 2020-12-17 09:09

I have an array of floats and I would like to convert it to an array of doubles in Java. I am aware of the obvious way of iterating over the array and creating a new one. I

3条回答
  •  Happy的楠姐
    2020-12-17 09:50

    Do you actually need to copy your float array to a double array? If you are having trouble with the compiler and types when using the floats you can use this...

    float x = 0;
    double d = Double.valueOf(x);
    

    What advantage do you get by taking a copy? If you need greater precision in the results of computations based on the floats then make the results double. I can see quite a lot of downsides to having a copy of the array, and performing the copy function, especially if it is large. Make sure you really need to do it.

    HTH

提交回复
热议问题