Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

float division

Status
Not open for further replies.

atferraz

Technical User
Aug 23, 2003
129
PT
How can I get the full result of two floats?

x/y and x%y on tha same result
 
If you are dividing floating point numbers, then the result of the division will be returned including both the whole and the decimal portions.

For example in the following code, res will be 1.5:
Code:
float res = 7.5f / 5.0f;

If you are having problems with something, give some more details about what exactly you are trying and how the results are different from what you expect.
 
Use ANSI Std library function:
Code:
double modf( double x, double *intptr );
For example:
Code:
double x = ...;
double y = ...;
double ipart, fpart;
fpart = modf(x/y,&ipart);
Avoid using float type in math calculations, use double.
See fmod() description for signs of integer/fractional portions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top