But i still get 1.000 or 2.000 only without decimal digits _________________ Eng. Haytham Shyouk
B.A. Electronics Engineering
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Sun May 03, 2009 3:52 pm
Quote:
y=x/100;
i still get 1.000 or 2.000 only
You are doing integer math. If you divide one integer (x) by another
integer (100), the result is an integer.
If you want a floating point result, you must make one of the numbers
in the divison expression into a float. Example:
Quote:
y=x/100.0;
You didn't show any of your variable declarations. 'y' should be declared
as a 'float'. 'x' should be declared as an 'int16' if you are using the A/D
in 10-bit mode. Also, if 'x' is an 'int16', then you should use "%lu" to
display it in printf.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum