Solved

bcb4 ROUND(x,2)

Posted on 2000-04-17
3
254 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

920 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

15 Experts available now in Live!

Get 1:1 Help Now