For a calculation in a C program, running on ESP32, I have to multiply and divide the following integers in the following way :
150 × 10000 ÷ 155 ÷ 138 × 100 ÷ 220 × 100
which produces 3100.000000 for a float variable and 3100 for a 32-bit unsigned integer.
I tried to test the result of the calculation on https://www.onlinegdb.com/ using the following code :
int main () {
float calc = 150 * 10000 / 155 / 138 * 100 / 220 * 100 ;
printf ( "calc = %f\n", calc ) ; // 3100.000000
uint32_t calc0 = 150 * 10000 / 155 / 138 * 100 / 220 * 100 ;
printf ( "calc0 = %u\n", calc0 ) ; // 3100
}
which again produces 3100.000000 for the float and 3100 for the 32-bit unsigned integer.
If I enter the same numbers in the calculator on my handy or laptop, the result is in both cases 3187,555782226.
So, I have an accuracy loss on the ESP32 of ( if I haven't messed up the formula ) ca. (3187−3100)÷3187×100 ~= 2,73 %
Where and how does the difference come from and is it possible to get the exact result on a 32-bit microcontroller as on the PC ?