Solved

bcb4 ROUND(x,2)

Posted on 2000-04-17
3
257 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
[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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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++.

739 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