I just posted about this and realized, it deserves a thread all its own!
One gap that I have always found in coding (be it for my new Arduino toy, or in general) is that there are lots of routines for doing abstract math, or doing bitwise math etc.
What I haven't seen, and would love to, is a library or even a guide, on dealing with measured data. What I remember for physics class is that measurements have uncertainty and uncertainty HAS to be quantified for results to be meaningful.
Take my tmp36. The data sheet says that it is accurate to 1 C (or as my physics teacher would point out "1 degree C, which we will assume means 1 C since we have never heard of such a unit "degrees Celsius") however the example code, puts out readings like "25.12 C"
Clearly that should round to 25. Though, I could easily make a special purpose rounding function for this, but it seems like something that should have a more generic solution. Especially since we were always taught to calculate first, calculate final significant figures and THEN round the values. So I should display 25 but, in multiplication (say by the measured volume of liquid) I want to use 25.12 with 2 sigfigs. (that is correct right? its been a while)
Has anyone tackled this problem? Whats the "best practice"? Just take each situation on a case by case basis? Is there a library that I have failed to find?
Good question. Does C/C++ have a round function? I know mos forms of Basic do. Maybe this can be added to future versions of the Arduino. May be worth mentioning in the Uno Punto Zero section of the forum. Then again it wouldn't be hard to implement a simple library to handle it for now.
add 0.5 and then truncate.
Or if it is in the lower figures, multiply by a power of ten, add 0.5, truncate (make an integer) then divide by a power of 10.
In general you should display to no more accuracy than your measurement, but then it depends on what you want to do with the result.
We do say degree celsius here in scandinavia, mostly we skip the celsius part and say degrees.
The manufacturer can not garantee grater accuracy than 1C and so can't we neither without calibration in the range of our mesurements with a better thermometer, that is more precise and accurate.
More because of standard error in mesurments.
It makes no sense using more than whole digits with that sensor off the box. the methods of manufacturing probably inhibit total lineraity of the final product (cheap methods, not constant deposit of material)
The sensor can be precise to 3 or 4 digits but without accuracy it is of no use.
[edit]The trunc() function rounds x to the nearest integer not larger in absolute value.
[/edit]