Go Down

Topic: division (Read 639 times) previous topic - next topic

el_supremo

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).

Pete

Rian

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 ??

robtillaart


x = x + roundingNr; 
x = int(x*Factor)/Factor;

homework: find the two variables roundingNr and Factor ...
Rob Tillaart

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

John_S

Quote
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

http://arduino.cc/en/Reference/Double

el_supremo

Oooops. Thanks John.

Pete

Go Up