Page 1 of 1

Floating Points

Posted: Sat Jan 19, 2019 4:33 pm
by gavo4
Hi Leigh,

Hope all is well!,

I need some help with a floating point please..;-), somehow I can't seem to get the second decimal.(I get just .0)

I have a very simple routine look at an interrupt on the Standard PIC MIAC and I am using I8 with RB2

I have a calculation counting my pulses (working 100%),

I then have a calculation of a Floating Point dividing my pulses (count variable so I can see the exact litres like 2.5L when I get 5 pulses) and I then convert the floating point variable to a string showing a single decimal place. When I read 5 pulse I get 2.0 so something is not right,

Any ideas where I have gone wrong?, code attached..;-)

Regards,

Gavin

Re: Floating Points

Posted: Sat Jan 19, 2019 5:41 pm
by mnf
Hi Gavin,

It's the way C works. The problem is here:
Capture.JPG
Capture.JPG (18.99 KiB) Viewed 4868 times
- the calculation divides count by 2 - both integer values and then tries to convert the result ( integer 2) to a float.

The fix is easy - just change the 2 to 2.0 which will force the compiler to handle the calculation using floating point values..

Martin

Re: Floating Points

Posted: Sat Jan 19, 2019 7:21 pm
by gavo4
Perfect - thanks Martin -

You are a champion and it works perfectly now..;-)