I need to produce a log to base 10 with at least 4 decimal places. However, the log10 inbuilt function is giving the output with only two decimal places. What do I do? Is there a different function or a library that I can use?

  • How are you displaying the values? The number of decimal places you are seeing is probably a byproduct of the way you are converting them to strings, not of the underlying math. Most Arudino math is done with the float type, which should have about 6 or 7 decimal digits of precision.
    – Duncan C
    Mar 10, 2019 at 0:27
  • I was just using a Serial.print without specifying any precision. This works, thanks
    – Paddy
    Mar 10, 2019 at 0:46

1 Answer 1


You should be able to get 6 or 7 decimal places out of the Arudino float type. Try using Serial.print for floats with a number of decimal places. Something like this:

float x = log10(3.141592658);
Serial.print(x, 6);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.