# Board index » cppbuilder » Rounding issue

## Rounding issue

2004-12-30 07:42:48 AM
cppbuilder103
Hi all,
I'm currently using Turbopower's Systools in my project and among other
things I'm using the routine RoundToDecimal(). I've noticed however that if
I need to round from a fractional number to an integer that this routine
doesn't work correctly.
For example I will call the routine like this:
double n = 40.46;
int p = 0;
double result = RoundToDecimal(n, p, false);
The false turns off bankers rounding (5 or more rounds up, 4 or less rounds
down, just like in gradeschool). In this example it will return a double
with the value of 41 instead of 40.
Does anyone know of a routine that I could use that would round a double to
an integer correctly without using bankers rounding? Thanks.

## Re:Rounding issue

#include <math.h>
result = floor(n);
// or
result = ceil(n);

## Re:Rounding issue

These routines always round up or down regardless of what the fractional
part of the number is. That's NOT what I need. I want a routine, that will
look at the tenths place of the fraction and round up if it's 5 or greater,
and round down if it's 4 or less.
"OBones" < XXXX@XXXXX.COM >wrote in message
##### Quote
#include <math.h>

result = floor(n);

// or

result = ceil(n);

{smallsort}

## Re:Rounding issue

The vcl has RoundTo (bankers rounding) and SimpleRoundTo (no bankers
rounding).
/Palle

## Re:Rounding issue

Thanks that's what I needed. A simple thing but for some reason, I couldn't
find it in the help, so thanks again for pointing it out.
"Palle Meinert" < XXXX@XXXXX.COM >wrote in message
##### Quote
The vcl has RoundTo (bankers rounding) and SimpleRoundTo (no bankers
rounding).

/Palle

## Re:Rounding issue

Isaac Church wrote:
##### Quote
These routines always round up or down regardless of what the fractional
part of the number is. That's NOT what I need. I want a routine, that will
look at the tenths place of the fraction and round up if it's 5 or greater,
and round down if it's 4 or less.
floor((n*10+5)/10)