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
Floating Points
-
- Valued Contributor
- Posts: 1191
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: Floating Points
Hi Gavin,
It's the way C works. The problem is here:
- 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
It's the way C works. The problem is here:
- 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