On Thu, 2 Feb 2006 20:13:09 +0100, "ME" <me@home.com> wrote:
What is the fastest way of getting the fraction part of a floating point
number?
So, if I have a float 10.3 I want to get a float with value 0.3 fast.
Thanks
From MS help. Convert to C++ style if you like.
Use 1.0 as the "y" number to get the fractional part.
double x = div(10.3, 1.0);
// result: x = 0.3;
/* DIV.C: This example takes two integers as command-line
* arguments and displays the results of the integer
* division. This program accepts two arguments on the
* command line following the program name, then calls
* div to divide the first argument by the second.
* Finally, it prints the structure members quot and rem.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void main( int argc, char *argv[] )
{
int x,y;
div_t div_result;
x = atoi( argv[1] );
y = atoi( argv[2] );
printf( "x is %d, y is %d\n", x, y );
div_result = div( x, y );
printf( "The quotient is %d, and the remainder is %d\n",
div_result.quot, div_result.rem );
}
Output
x is 876, y is 13
The quotient is 67, and the remainder is 5