I have some code that I run on an ESP32 written in Arduino. The problem is that my result is rounded up when it should not be.
float step_value = (float)abs(levels_values[i] - levels_values[i - 1]) / abs(levels_percentages[i] - levels_percentages[i - 1]);
float percentage_diff = (float)abs(current_value - levels_values[i - 1]) / step_value;
Serial.println(step_value);
Serial.println(2.00/step_value);
Serial.println(2.00/0.07);
And inside the console the output is:
0.07
30.00
28.57
Why is that if I divide by the variable, I get a rounded value and when I divide by the value of the variable I get the right value.
levels_values and levels_percentages vectors are of type int