How to set double precision in arduino without c/c++ libraries

I just want to know how i can adjust double precision/ the number of digits, currently i have two digits but i want to have only one, i did a bit of research and found out it's pretty easy in c++ with the library but unfortunately they are not supported by atmel, so i just want to know how can i adjust the precision without the library?
Possibly with a string and format specifiers?

look up sprintf modifiers

AVR based Arduinos do single precision floating point (6-7 digits total accuracy), even if you specify double , but those with other types of microprocessors support double precision (about 15 digits).

Serial.print(value, n): n specifies number of digits past the decimal point (default 2).

That's the number of digits to print, which is different that the number of digits that are "valid" in the value... (in case that wasn't clear to OP.)

Yeah i need to change number of digits in variable because i'll print that value to a display.

If display print method does not have overload where you can specify number of decimals, then use sprintf to format it

Thanks i will try it.

sprintf does not support floats on many arduinos.

Are you asking about Serial.print()? As in:

Serial.print(1.23456, 0) gives "1"
Serial.print(1.23456, 2) gives "1.23"
Serial.print(1.23456, 4) gives "1.2345"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.