So let's say I have a simple array of float numbers
[0.315023, 1.0, 0.12345, 0121111]
And call it arr1.
I need to take this array and turn it into this:
[0.3150, 1.0000, 0.1234, 0.1211] *Please note that 1.0 is now 1.0000 and 0.3150 has a 0 at the end
I have tried using a for loop to iterate through the array and rounding the numbers as follows:
// i representing a number in the arr1; let's imagine that "newNum" replace the original numbers in arr1 float newNum = Math.round(i*10000.0000)/10000.0000;
What will result is following:
[0.315, 1.0, 0.1234, 0.1211]
As you can see, the first item is missing the 0 at the end, and the second item is missing a lot of zeros at the end.
I have tried to use DecimalFormat, but it doesn't work with the float array; also I am not trying to format decimals, I am rounding them. (although I have tried the round first then format second; which didn't work because of difference in datatype).
PLEASE for the love of God, help me. This is like the last thing I need to complete for my project. I am so close! Thank you so much in advance!
*PS: I need to make sure the array remains FLOAT; I need to use the data in the array later on.