# [R] - round() strange behaviour

John Logsdon j.logsdon at quantex-research.com
Sat Aug 4 23:57:28 CEST 2007

```I must admit I had never realised this so thanks to Monica for raising it.

Round-to-even is used for statistical reasons and there is some point as it
obviously reduces bias.  But why should the decision  be to round to the
nearest even number?  rounding to the nearest odd number would be equally
valid.  (signif(x,0) is the same as round(). )

There is a debate and sometimes you need symmetric rounding.  Perhaps there
should be an option in round that defaults to round-to-even for compatibility
but includes the various other rounding approaches as seen for example in
http://en.wikipedia.org/wiki/Rounding

BTW with Fortran the 'nearest integer' approach is used:

REAL*8 TEST
10    CONTINUE
WRITE(*,*)TEST,IDNINT(TEST)
GOTO 10
END

Compiling this under g77 and gfortran gives the result:
~ \$ g77 idnint.f -o idnint
~ \$ ./idnint
1.5
1.5 2
2.5
2.5 3

~ \$ gfortran idnint.f -o idnint
~ \$ ./idnint
2.5
2.50000000000000                3
1.5
1.50000000000000                2

Octave:

octave:1> round(1.5)
ans = 2
octave:2> round(2.5)
ans = 3

On Thursday 02 August 2007 21:46:36 Monica Pisica wrote:
> Hi again,
>
> Mea culpa for not reading help pages before hand - but one would not go
> there when the function syntax is obvious and known .... besides other
> programming languages (for example IDL) with same function do not round to
> the next even number .... so i do get 3 for round(2.5), and i didn't
> realize that it is "normal" for R to give a 2 instead of 3.> Date: Thu, 2
> Aug 2007 22:38:49 +0200> From: Achim.Zeileis at wu-wien.ac.at> To:
> pisicandru at hotmail.com> CC: r-help at stat.math.ethz.ch> Subject: Re: [R] -
> round() strange behaviour> > On Thu, 2 Aug 2007, Monica Pisica wrote:> > >>
> > Hi,> >> > I am getting some strange results using round - it seems that
> it depends if the number before the decimal point is odd or even ....> >> >
> For example:> >> > > round(1.5)[1] 2> round(2.5)[1] 2> > While i would
> expect that round(2.5) be 3 and not 2.> >> > Do you have any explanation
> for that?> > Yes: you obviously did not read the man page! Please do.> Z> >
> > I really appreciate your input,> >> > Monica> >> >> >
> _________________________________________________________________> >
> [[trailing spam removed]]> >> > [[alternative HTML version deleted]]> >> >
> ______________________________________________> > R-help at stat.math.ethz.ch
> mailing list> > https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do
> read the posting guide http://www.R-project.org/posting-guide.html> > and
> provide commented, minimal, self-contained, reproducible code.> >> >>
> _________________________________________________________________
> Messenger Café — open for fun 24/7. Hot games, cool activities served
> daily. Visit now.
>
> 	[[alternative HTML version deleted]]

--
Best wishes

John

John Logsdon                               "Try to make things as simple
Quantex Research Ltd, Manchester UK         as possible but not simpler"
j.logsdon at quantex-research.com              a.einstein at relativity.org
+44(0)161 445 4951/G:+44(0)7717758675       www.quantex-research.com

```