Go Down

Topic: DS18B20 - Round Temperature (Read 3590 times)previous topic - next topic

gnusso

Mar 09, 2013, 09:49 am
Hi All,
I'm using DS12B20, with the example I've the temperatura displayed like this :

12.23

20.37

etc etc

I would like to round the temperature for example see:

12.20

20.40

Is possible ? Thanks for the information,

Gnux

UKHeliBob

#1
Mar 09, 2013, 09:59 am
Is http://playground.arduino.cc/Code/PrintFloats any help ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

gnusso

#2
Mar 09, 2013, 11:35 am
Ciao UKHeliBob,
Thanks you for the link, I've play a little bit with it ... but I would like print on my display and not on Serial ...

But is not possible to pass printFloat() function to LCD.print() function ...

any other ideas ?

I was thing to convert in string and then take left string could be possible ?

Regards,
Andrea

PaulS

#3
Mar 09, 2013, 02:00 pm
Which LCD library are you using? Does it derive from the Print class?

gnusso

#4
Mar 09, 2013, 02:13 pm
Hi,
i'm using LiquidCrystal.h

Regards,
Gnux

robtillaart

#5
Mar 09, 2013, 02:58 pm
round the number e.g. by moving to integer domain.

pseudo code
Code: [Select]
`float temp =12.34int t = temp * 10 + 0.5;  // t = 123   (.9)  t is temp in tenthsprint t/10;  // integer partprint .print t%10;  //decimal partprint 0;`

(if temp < 0 code might differ slightly)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

#6
Mar 09, 2013, 03:45 pm
From LiquidCrystal.h:
Code: [Select]
`class LiquidCrystal : public Print {`
So, LCD.print(someFloat, 1);
will show someFloat on the LCD rounded to one decimal place.

robtillaart

#7
Mar 09, 2013, 05:44 pm
The OP wants a trailing zero
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

gnusso

#8
Mar 09, 2013, 06:00 pm
Thanks Guys for the suggest,
I will try and then I'll let you know ...

Have nice week end,
Gnux

gnusso

#9
Mar 09, 2013, 06:31 pm
Yes It's working with the round suggest by Paul !

Thanks you again,
Regards,
Gnux

UKHeliBob

#10
Mar 09, 2013, 09:30 pm
Does it round or does it truncate ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

robtillaart

#11
Mar 09, 2013, 10:49 pm
from print.cpp

Code: [Select]
` // Round correctly so that print(1.999, 2) prints as "2.00"  double rounding = 0.5;  for (uint8_t i=0; i<digits; ++i)    rounding /= 10.0;`

rounding it does
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up