Hello
I wish to calculate the precentage of an integer number in C18 compiler. I understand that floating point can be used. However I have read elsewhere on the internet that floating point arithmatic should be avoided as much as possible as its very CPU intensive...especially for PICs.
However, due to my limited knowledge I can not understand other than to simply use floating point.
Below are few lines of C18 code which show my understanding so far of how the precentage can be calculated.
Please can someone look at my code and correct it. Also please provide me feed back for any better and more efficient way of calculating the precentage of a number.
Thank you
Haseeb
I wish to calculate the precentage of an integer number in C18 compiler. I understand that floating point can be used. However I have read elsewhere on the internet that floating point arithmatic should be avoided as much as possible as its very CPU intensive...especially for PICs.
However, due to my limited knowledge I can not understand other than to simply use floating point.
Below are few lines of C18 code which show my understanding so far of how the precentage can be calculated.
Please can someone look at my code and correct it. Also please provide me feed back for any better and more efficient way of calculating the precentage of a number.
Thank you
Haseeb
Code:
float precentage = 0; //declaring float variable
precentage = (0x5555/0x8888) * 100.0; //calculating the percentage