0

The help of round states that ‘go to the even digit’ is used for rounding.

How can I have a consistent rounding mechanism?


For example:

This rounds up.

round(1.5, 0)

2

This rounds down.

round(4.5, 0)

4

In both cases I want it to round up.

But I also want 1,4 to round down and 1,7 to round up.

SeGa
  • 9,454
  • 3
  • 31
  • 70
  • `floor(x + 0.5)`, with some corner cases – Mad Physicist Sep 13 '19 at 13:56
  • 1
    Take a look at this [issue](https://stackoverflow.com/questions/12688717/round-up-from-5) – slava-kohut Sep 13 '19 at 13:57
  • Before implementing this, you should think about whether you *really* need to always round up. There are good reasons that `round` works the way it does - to avoid bias. Have alook at https://en.wikipedia.org/wiki/Rounding – dww Sep 13 '19 at 14:15

1 Answers1

0

There is the functions floor() and ceiling()

floor(1.5)

1

ceiling(1.5)

2