Hello,
I am using the Serial Monitor as a troubleshooting tool for my sketch. I must verify my math among other things. The monitor won't display more than 2 decimal places when reading a float var. I assume it is rounding. I could probably modify it if I just knew where 'rounding' is located. I've searched Arduino.cc, the forum, googled it and can't find anything. Has anyone else solved this problem?
1oldfox:
Hello,
I am using the Serial Monitor as a troubleshooting tool for my sketch. I must verify my math among other things. The monitor won't display more than 2 decimal places when reading a float var. I assume it is rounding. I could probably modify it if I just knew where 'rounding' is located. I've searched Arduino.cc, the forum, googled it and can't find anything. Has anyone else solved this problem?
Thanks in advance,
-oldfox-
"If it ain't broke, fix it 'til it is."
No you just add a second optional argument to the serial.print statement that tells it how many digits to the right of the decimal place you wish to be printed:
Syntax
Serial.print(val)
Syntax
Serial.print(val)
Serial.print(val, format)
Parameters
val: the value to print - any data type
format: specifies the number base (for integral data types) or number of decimal places (for floating point types)
Parameters
val: the value to print - any data type
format: specifies the number base (for integral data types) or number of decimal places (for floating point types)
So assuming your val is a floating point variable and you wished to print four digits after the decimal point the statement would look like this:
Serial.print(val, 4); // print floating point variable showing four digits after decimal point.