Solved

bcb4 ROUND(x,2)

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

808 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