hello anyone here wants to help me...i want the return value to be rounded off for example: TotalComponent=235 PartialComponent=90 per=38.3%
but with this function i always get 0 % anyone here want to sugest what should be done
unsigned int CalculatePercentage(int TotalComponent,int PartialComponent){ int per; per= (PartialComponent/TotalComponent)*100; return (float)per; }
per = CalculatePercentage( 235, 90 ); printf( "Percent %d", per );
the return value is 38% the .3 is disregarded
As Mike says, the reson for this should be obvious - it's textbook stuff.
main() { float per; per = CalculatePercentage( 235, 90 ); printf( "Percent %f", per ); }
How have you checked the return value?
Obviously, if the return value has been truncated before calling printf, then just changing the format specifier in the printf cannot magically re-generate the discarded information!
Or maybe you just changed your source code, and forgot to rebuild it...?
PS Note how the addition of a little whitespace makes your code so much easier to read!