xtvca
asked on
bcb4 ROUND(x,2)
I'm trying to cut my float values to 2 decimals precision somthing like 1.2345 to be 1.23
I found the ROUND function in borland c++ builder help but when i try to implement this function i'm getting error about function name (ROUND)
i also included math.h but it still dont work
I know that i can multiply my nuber with 100 and then roundit down to 0 decimal places and then devide it with 100 to get what i need but it is to messy
What's wrong with ROUND
Regards,Vedran
I found the ROUND function in borland c++ builder help but when i try to implement this function i'm getting error about function name (ROUND)
i also included math.h but it still dont work
I know that i can multiply my nuber with 100 and then roundit down to 0 decimal places and then devide it with 100 to get what i need but it is to messy
What's wrong with ROUND
Regards,Vedran
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for details
Regards
Vedran
Regards
Vedran
You could use the floor() and ceil() functions.
#include <math.h>
#include <stdio.h>
int main(void)
{
double number = 123.54;
double down, up;
down = floor(number);
up = ceil(number);
printf("original number %5.2lf\n", number);
printf("number rounded down %5.2lf\n", down);
printf("number rounded up %5.2lf\n", up);
return 0;
}