I want the operator to take off fractionnary part of a real number
ex 23,345 ------->23
I want the operator to take off fractionnary part of a real number
ex 23,345 ------->23
>> operator <<
Well, there is no operator for that (or at least not to my knowledge). You'll probably just have to write a function to do that.
--Garfield
1978 Silver Anniversary Corvette
I think you meant "." instead of "," ... anyway:
float a;
int b;
a = 23.456;
b = (int) a;
a = (float) b;
Problem solved.
/**
*** EDIT:
**/
Actually:
a = (int) a;
That should work.
/**
*** END EDIT.
**/
Quzah.
Hope is the first step on the road to disappointment.
Oh, if you meant "." then quzah is right. I thought you wanted to round off or something.
The reason being is because a float that is typecasted to an int can't support the fractionality of the float so it cuts it off. Just a little insight of why that happens.
--Garfield
1978 Silver Anniversary Corvette
One way is to use the floor() function in math.h
Code:#include <stdlib.h> #include <stdio.h> #include <math.h> int main(void) { double d = 23.345; d = floor(d); printf("d:%lf\n",d); return 0; }
You seek Yoda
Or this
-----
#include <math.h>
double modf(double VAL, double *IPART);
float modff(float VAL, float *IPART);
Description
------------
`modf' splits the double VAL apart into an integer part and a
fractional part, returning the fractional part and storing the integer
part in `*IPART'. No rounding whatsoever is done; the sum of the
integer and fractional parts is guaranteed to be exactly equal to VAL.
That is, if . REALPART = modf(VAL, &INTPART); then
``REALPART+INTPART'' is the same as VAL. `modff' is identical, save
that it takes and returns `float' rather than `double' values.
-----