Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# C++Builder3,function ROUND

Posted on 1998-07-28
Medium Priority
229 Views
I want to use the function ROUND which is described in the Help section. I cannot find a headerfile fitting to this function. Who knows how to invoke it?
0
Question by:eeks2
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 22

Expert Comment

ID: 1168829
I searched through all the include files in the include directory and its descendant directories and could not find it!

You might want to look at some of the round functions provided in the SysDefs.h file in the VCL directory.
0

Author Comment

ID: 1168830
The function I am searching for is a function that rounds a double or extended variable to one digit after the decimal point.
like ROUND does, (ROUND(Value,Precision)), whose prototype I cannot find.
0

LVL 22

Accepted Solution

nietod earned 400 total points
ID: 1168831
The following should be a good start to writting your own version.  It is not tested by should be close.  I'm not sure it handles negatives in the correct mathematical way (I can't remember the rule.)  It does not check that the precission is valid ( >0).

double RoundToInt(double x)
{
double RetVal = floor(x);

if (x -RetVal >= 0.5)
RetVal = ceil(x);
return RetVal;
}

double Round(double x,int p)
{
double m = pow(10,p);

x *= m;
x = RoundToInt(x);
x /= m;
return x;
}
0

Author Comment

ID: 1168832
Works fine even with negative values. Thank You!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
###### Suggested Courses
Course of the Month9 days, 7 hours left to enroll