The simplest way to get more decimal places to print is this:
Serial.println(val,NUMBER_OF_DECMIAL_PLACES);
This will print out any number of digits after the decimal place. Regular print without the number of digits specified will default to 2 decimal places. for example, here is some code and the result that gets printed:
float val = 23.459;
Serial.println(val);
Serial.println(val, 4);
Serial.println(val, 10);
23.46
23.4590
23.4589996337
You may notice that with 10 decimal places printed you can start to see how much the actual value of 23.459 needs to be approximated to fit within a floating point number. This is similar to how 1/3 can not be represented 100% accurately in a finite number of decimal digits; 459/1000 cannot be represented 100% accurately in a finite number of binary bits, so it is approximated.
Also, note that for non-floating point numbers the optional second argument to print
and println
is the base it should be printed in (dec, hex, oct, ...) and has nothing to do with precision.