Hi all.
I'm doing some maths to extract some float values stored as ascii in a byte array from another system.
When I extract (say) the 10ths value from the array and add it to the current integer total I get an erroneous value from the add function.
1000.000 + 0.900000 = 1000.900024
Thanks for all the replies.
I am only interested in three places of accuracy - is there a cheap way to round the results when performing addition etc so as to avoid the errors?
Where's the code that uses the results? How do you use the results?
The cheapest way to do it is to let it calculate as it will and use just the three significant figures/ three decimal places, or whatever at the end of the calculation.
If your calculations depends on/is affected by the least significant bits of error, you may need to pay more attention to numerical methods
Errors in floating point operations cannot be avoided. They must be understood, and your program has to be written accordingly.
If you need higher accuracy in your calculations, use type double instead of float, where you get 15 to 16 digits of accuracy in the decimal representation. AVR-based Arduinos like the Uno, Mega, etc. do not support type double, by default.