Floating Points

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
gavo4
Posts: 92
Joined: Sat Aug 25, 2018 7:58 pm
Been thanked: 8 times
Contact:

Floating Points

Post 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
Attachments
Water_Meter_V1.fcfx
(15.56 KiB) Downloaded 244 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Floating Points

Post by mnf »

Hi Gavin,

It's the way C works. The problem is here:
Capture.JPG
Capture.JPG (18.99 KiB) Viewed 4558 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

gavo4
Posts: 92
Joined: Sat Aug 25, 2018 7:58 pm
Been thanked: 8 times
Contact:

Re: Floating Points

Post by gavo4 »

Perfect - thanks Martin -

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

Post Reply