ccs complier float issue with pic18f4620

Status
Not open for further replies.

raman00084

Full Member level 6
Joined
Nov 29, 2010
Messages
362
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,006
float32 a = 100/1000;

printf(%f,a)

the result is 0.00


if i change

float32 a =1000/1000

the result is 1.0


kindly help
regards
kalyan
 

The result is correct according to C type propagation rules and will be obtained with any C compiler. 100/1000 is calculated as integer division (result 0) and then converted to float.

You may want to write e.g.:
Code:
float32 a = 100.0/1000;
float32 a = 100/1000.0;
float32 a = float(100)/1000;

In any case, at least one of the numbers must be of the float type to cause a float division.
 
Yes, true indeed.

Typecast has higher priority than arithmetic operation, one pair of brackets can be omitted.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…