(Read 639 times)
Mar 09, 2012, 04:44 am
One way ot fix it is to change 1024 to 1024.0 which will then force the division as floating point instead of integer.
And declare X to be float or double. Float gives about 6 digits of precision and double gives about 12 (IIRC).
You will also have to change Serial.print( X, DEC); to Serial.print( X, 4); so that X is printed as a floating point number with 4 digits after the decimal point (or however many you want).
Mar 09, 2012, 04:57 am
thanks for that . well can i do like if i have x= 0.26 how can i make it = 0.3 which to a proximation value ??
In theory there is no difference between theory and practice, however in practice there are many...
Mar 09, 2012, 07:59 am
x = x + roundingNr;
x = int(x*Factor)/Factor;
homework: find the two variables roundingNr and Factor ...
Nederlandse sectie -
(Please do not PM for private consultancy)
Sometimes teaching, always learning,
Mar 10, 2012, 04:34 am
Float gives about 6 digits of precision and double gives about 12 (IIRC).
Although that may be the case in other programming languages, in Arduino float and double are essentially the same
Mar 10, 2012, 05:03 am
Oooops. Thanks John.