How to print a float with 3 decimal places
i can not figure out syntax print float has 3 decimal places. found useful snippet of code float value keypad:
to print lcd tried this:
but doesn't print right of decimal. there simple way this?
code: [select]
while (1) { //get digits
byte digit = checkkeybuffer(); //get keypress user
if (digit >= 0 && digit <= 9) { //a digit
if (dp == 0) {
entry = entry * 10;
entry = entry + digit;
}
if (dp > 0) {
digit = digit / pow(10, dp);
digit = entry + digit;
dp = dp + 1;
}
break;
}
else if (digit == keyasterisk) { //decimal point
dp = 1;
break;
}
} //end while getting digits
to print lcd tried this:
code: [select]
sprintf(thebuffer, "%03d", entry);
disp.lcd_print(thebuffer);
but doesn't print right of decimal. there simple way this?
"%d" integers, %f not work on arduino space reasons. try dtostrf().
Arduino Forum > Using Arduino > Programming Questions > How to print a float with 3 decimal places
arduino
Comments
Post a Comment