Functions for real and fractional part of a number
Are ther any functions in C++, which determines the real and fractional part of a given number. If so Please let me know.
Are the any such division operator which gives results like 7/3 = 3 NOT 2.33! It means that any fractional part if exist should be truncated to the higher number.
thankx
Re: Functions for real and fractional part of a number
Its very easy:
double a = 7.33,c;
long b;
//Real part:
b = (long)a;
//Fractional part
c = a - b;
//Converting to higher number (result in b)
if (b<a) b++;
WBR Oak
Re: Functions for real and fractional part of a number
#include <math.h>
double a = 7, b = 3;
double c = ceil(a/b);
Regards,
Paul McKenzie
Re: Functions for real and fractional part of a number
modf will separate a double into its fractional and integer parts.
As mentioned before, ceil will round up to next highest integer.
For more info on these see the "Floating-Point Support Routines"
section in the docs.