|
-
April 11th, 1999, 05:24 AM
#1
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
-
April 11th, 1999, 07:53 AM
#2
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
-
April 11th, 1999, 12:01 PM
#3
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
-
April 12th, 1999, 12:54 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|