How to set my Lcd to display X and Y for whole number but no decimals?
It helps to post all your code and please NEVER post code as an image as it is imposable to copy and paste. Anyway replace the lines that do the printing with :-
lcd.print((int)x);
lcd.print((int)y);
oh okay thanks bro
If you want the value rounded instead of truncated, specify 0 decimal digits instead of the default 2:
void setup()
{
Serial.begin(115200);
delay(200);
float x = 1.66;
float y = 1.44;
Serial.print((int)x);
Serial.print(", ");
Serial.println((int)y);
Serial.print(x); // Defaults to 2 decimal places
Serial.print(", ");
Serial.println(y); // Defaults to 2 decimal places
Serial.print(x, 1);
Serial.print(", ");
Serial.println(y, 1);
Serial.print(x, 0);
Serial.print(", ");
Serial.println(y, 0);
}
void loop() {}
Output:
1, 1
1.66, 1.44
1.7, 1.4
2, 1
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.