Temperature display - precision

Hi;
On my LCD display temperature is two decimal places:
24.87C
How I can change it to:
24C
or
24.00C

(ArduinoUno, LCD4x20 with I2C, Libraries: DallasTemperature, LiquidCrystal_I2C, OneWire)

Thx in advance

Post your code!

And read up about the round() function.

Here it is:

#include "OneWire.h"
#include "DallasTemperature.h"
#include "dht.h"
#include <Wire.h> 
#include "LiquidCrystal_I2C.h"

LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x3F for a 20 chars and 4 line display


dht DHT;

#define DHT11_PIN 7

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
 
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);




void setup()
{
  lcd.init();                      // initialize the lcd   
  lcd.backlight();
  sensors.begin();

}



void loop()
{
  delay(1000);
  int chk = DHT.read11(DHT11_PIN);

lcd.setCursor(0,0);
lcd.print("Dock Weather");
  
  lcd.setCursor(0,1); 
  lcd.print("Air Temp.: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  
  lcd.setCursor(0,2);
  lcd.print("Air Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");

  lcd.setCursor(0,3); 
  sensors.requestTemperatures(); // Send the command to get temperatures
  lcd.print("Water Temp.: ");
  lcd.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
  lcd.print((char)223);
  lcd.print("C");
    delay(1000);
}

If it is really 24.87 do you really want to display it as 24.00 ?

lcd.print(floor(24.87));

prints 24.00

lcd.print(round(24.87));

prints 25

  lcd.print(round(floor(24.87)));

prints 24

lcd.print((int)24.87);

prints 24

Take your pick

The following codes (belong to LM35 under UNO and Vref = 1.1V0) show only the integer part of the ambient temperature. To see the fractional part, change the data type to float.

unsigned long temp = 100*(1.10/1024)*analogRead(A5);//ADCT;
Serial.println(temp, DEC);

@GolamMostafa: This is completely unrelated to the OP's question. He uses a DHT11 sensor which provides a digital output.

@OP: UKHeliBob did provide the correct information.

The intention of my codes are to show a way of avoiding the printing of the the fractional part of the result.

GolamMostafa:
The intention of my codes are to show a way of avoiding the printing of the the fractional part of the result.

but didn't leave room for the possibility of a negative temperature

In our locality, it is hard to experience negative temperature.

GolamMostafa:
In our locality, it is hard to experience negative temperature.

no freezers where you live, then? :wink:

We have almost everything fresh!

GolamMostafa:
We have almost everything fresh!

Well, the rest of the world (except where you live, where there is no refrigeration or or sub-zero scientific studies) may sometimes come across temperatures below zero... FYI.

now you know!

Thx to all;
Functions round() and floor() works OK.

However, I’m wondering if this can be done:
First reading 23.76C
with round function it is 24C
with

 lcd.print(DHT.temperature(1))

it is 23.7C
Is it possible to combine all together and get 23.8C reading?

Marmadoc:
Is it possible to combine all together and get 23.8C reading?

if you want to fool yourself into believing that your sensor is accurate to that level of precision, yes you can.

if you multiply the number by 10 and then round() it...

or you can roll your own function to roundToTenths().

Got your point BulldogLowell
You are absolutely right.
Thx