The result sould be 0.6 but it is 0.000 Why ??
pcm version is 4.13
plz help me
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
Posted: Thu Nov 08, 2012 10:23 am
Because you are not using float....
In _C_ nothing to do with CCS, if you perform a maths operation between two numbers, the compiler looks at the types of both numbers and uses the maths for the highest type. You have two 8bit integers in the source, so integer maths is used. If you change one number to be float, then float maths will be used, so:
ffl=open/100.0;
or
ffl=(float)open/100;
In the first case the constant divisor is made a float (adding a decimal does this). In the second, 'open' is 'cast' to a float before it is used.
This is standard C and any book on the subject should explain this.
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