Solved

C++Builder3,function ROUND

Posted on 1998-07-28
4
219 Views
Last Modified: 2010-04-02
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:nietod
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

by:eeks2
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

by:
nietod earned 100 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

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question