Offline
Sr. Member
Karma: 2
Posts: 354
|
 |
« on: March 09, 2013, 03:49:24 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
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Online
Edison Member
Karma: 49
Posts: 1439
May all of your blinks be without delay
|
 |
« Reply #1 on: March 09, 2013, 03:59:05 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 354
|
 |
« Reply #2 on: March 09, 2013, 05:35:47 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
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #3 on: March 09, 2013, 08:00:34 am » |
Which LCD library are you using? Does it derive from the Print class?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 354
|
 |
« Reply #4 on: March 09, 2013, 08:13:31 am » |
Hi, i'm using LiquidCrystal.h
Regards, Gnux
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 91
Posts: 9454
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #5 on: March 09, 2013, 08:58:27 am » |
round the number e.g. by moving to integer domain. pseudo code float temp =12.34 int t = temp * 10 + 0.5; // t = 123 (.9) t is temp in tenths print t/10; // integer part print . print t%10; //decimal part print 0;
(if temp < 0 code might differ slightly)
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #6 on: March 09, 2013, 09:45:24 am » |
From LiquidCrystal.h: class LiquidCrystal : public Print { So, LCD.print(someFloat, 1); will show someFloat on the LCD rounded to one decimal place.
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 91
Posts: 9454
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #7 on: March 09, 2013, 11:44:28 am » |
The OP wants a trailing zero 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 354
|
 |
« Reply #8 on: March 09, 2013, 12:00:18 pm » |
Thanks Guys for the suggest, I will try and then I'll let you know ...
Have nice week end, Gnux
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 2
Posts: 354
|
 |
« Reply #9 on: March 09, 2013, 12:31:45 pm » |
Yes It's working with the round suggest by Paul !
Thanks you again, Regards, Gnux
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Online
Edison Member
Karma: 49
Posts: 1439
May all of your blinks be without delay
|
 |
« Reply #10 on: March 09, 2013, 03:30:54 pm » |
Does it round or does it truncate ?
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 91
Posts: 9454
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #11 on: March 09, 2013, 04:49:50 pm » |
from print.cpp // 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
|
|
|
|
|
Logged
|
|
|
|
|
|