Go Down

Topic: Not Displaying decimal information (Read 601 times) previous topic - next topic

AngrytheClown

I am running a sketch where I am trying to capture and display on the LCD the High and Low temperatures. The following works ok, except the High & Low values have no decimal information. It displays like this:

A:22.9
H:24
L:22

Code: [Select]
int HighTempA = 0.1;
int LowTempA = 100;
void loop(){
   
  lcd.setCursor(0, 0);
  lcd.print("A:");
  sensors.requestTemperatures();
  lcd.print(sensors.getTempCByIndex(0), 1);

  if (HighTempA < sensors.getTempCByIndex(0)) HighTempA = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 1);
  lcd.print("H:");
  lcd.print(HighTempA, 1);
 
  if (LowTempA > sensors.getTempCByIndex(0)) LowTempA = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 2);
  lcd.print("L:");
  lcd.print(LowTempA, 1);
}

AngrytheClown

I tried both 1, & 0.1. Makes no difference in the final display on LCD.

Lsnyman

He just told you. You need to use float and not int.

marco_c

INTEGERS (int) are whole numbers only (no decimals).
FLOATING POINT (float) numbers include a decimal component.

If you want floating point you need to declare a variable as float, not int.
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

AngrytheClown

Thank you all for the nudge in the right direction, I got it working by changing out my int statements.

Go Up