Limiting Decimal Places For LCD Print?

My LCD is printing too many decimal places.

How would I print out something that looks like 24.56% to an LCD if the variable returned is a float or double?

nvm, I figured it out:

double gasReading = analogRead(gasPin);
gasReading = gasReading / 10;
lcd.print(gasReading);
lcd.print('%');
delay(3000);

double provides no more precision than float on the Uno or other ATMEGA boards, FYI

when you want to do float math you should do it like this:

  gasReading = gasReading / 10.0;

by default it should print two decimal places or try:

Serial.println(myFloat,4)

BulldogLowell:

Serial.println(myFloat,4)

That would give 4 decimals, but yep it should be 2 by default.

JimboZA:

BulldogLowell:

Serial.println(myFloat,4)

That would give 4 decimals, but yep it should be 2 by default.

Serial.print() - Arduino Reference

yup, just an example of how to print X places to the right of the decimal...

also... analogRead() returns an int from zero to 1023, FYI... though you can easily manipulate it with the map() function

for example if you want a percentage from zero to the output max (100%)

  int gasReading = map(analogRead(gasPin), 0, 1023, 0, 100);
  Serial.print(gasReading);
  Serial.println("%");

or, as a float with two decimal places:

  float myFloat = analogRead(gasPin)/1023.0*100.0;
  Serial.print(myFloat);
  Serial.println('%');