Solved

bcb4 ROUND(x,2)

Posted on 2000-04-17
3
253 Views
Last Modified: 2010-04-10
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
0
Comment
Question by:xtvca
3 Comments
 
LVL 1

Expert Comment

by:jbodom
ID: 2724018
All of the all upper case functions are not a part of the C++ language but routines in one of the ActiveX controls that comes with BCB.  

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;
 }
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 15 total points
ID: 2725811
ROUND is one of 125 functions of
Formaula 1 Worksheet. Help(vtss.hlp)
explains what it is and how use it.
That what you want:

double round(double a,int n)
{
  double a1 = a;
  for (int i = 0; i < n; i++)
    a1 *= 10.0;
  long i = long(a1+0.5);//round
  a1 = i;
  for (int i = 0; i < n;i++)
    a1 /= 10.0;
  return a1;
}
0
 

Author Comment

by:xtvca
ID: 2727711
Thanks for details
Regards

Vedran
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now