C
C
Chvalov2015-09-10 09:26:04
Java
Chvalov, 2015-09-10 09:26:04

float array to int, is it possible?

There is an array of float type, I need to get its value in int multiplied by 100
That is, if the float array has a value of 0.4, then in the int array it should be 40
How can I do this? Couldn't figure out anything understandable.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LeEnot, 2015-09-10
@Chvalov

float []arrFloat = {2.0, 0.1, 0.02};
int []arrInt = new int[3];
for(int i = 0; i < 3; i++){
    arrInt[i] = (int)(Math.round(arrFloat[i]*100))
}

That being said, when using just (int)(arrFloat[i]*100) you will get the problem of rounding negative numbers.

M
Mokhirjon Naimov, 2015-09-10
@zvermafia

Math.round(0.4 * 100)
Detailed .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question