Click to See Complete Forum and Search --> : Functions for real and fractional part of a number
Shahzad
April 11th, 1999, 05:24 AM
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
Oak
April 11th, 1999, 07:53 AM
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
Paul McKenzie
April 11th, 1999, 12:01 PM
#include <math.h>
double a = 7, b = 3;
double c = ceil(a/b);
Regards,
Paul McKenzie
Gomez Addams
April 12th, 1999, 12:54 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.