Skip to main content
added 27 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes.

In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits).

Only for e.g. Arduino Due: You can use doubles instead, see https://www.arduino.cc/reference/en/language/variables/data-types/double/

You might check for the strtod function, but I'm not sure if it is handled by the Arduino:

https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/strtod.php

If this doesn't work, you can use a function to split the '.' and process the left/right part to convert to an unsigned long and combine it together. But if there are exponential and minus signs involved it might get more difficult.

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes.

In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits).

You can use doubles instead, see https://www.arduino.cc/reference/en/language/variables/data-types/double/

You might check for the strtod function, but I'm not sure if it is handled by the Arduino:

https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/strtod.php

If this doesn't work, you can use a function to split the '.' and process the left/right part to convert to an unsigned long and combine it together. But if there are exponential and minus signs involved it might get more difficult.

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes.

In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits).

Only for e.g. Arduino Due: You can use doubles instead, see https://www.arduino.cc/reference/en/language/variables/data-types/double/

You might check for the strtod function, but I'm not sure if it is handled by the Arduino:

https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/strtod.php

If this doesn't work, you can use a function to split the '.' and process the left/right part to convert to an unsigned long and combine it together. But if there are exponential and minus signs involved it might get more difficult.

Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes.

In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits).

You can use doubles instead, see https://www.arduino.cc/reference/en/language/variables/data-types/double/

You might check for the strtod function, but I'm not sure if it is handled by the Arduino:

https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/strtod.php

If this doesn't work, you can use a function to split the '.' and process the left/right part to convert to an unsigned long and combine it together. But if there are exponential and minus signs involved it might get more difficult.