Is there a library function that rounds a number towards the infinities (i.e. away from 0)

java, math

Solution

How about

rounded = Math.ceil(Math.abs(toBeRounded)) * Math.signum(toBeRounded);

That rounds the absolute value of your number up, then re-applies the signum.

Problem

I need a rounding function that returns a larger integer when the input is positive and the a smaller number when negative, i.e. it should not return 0 unless the input is actually 0.0. Examples: ``` f(0.1) = 1 f(-0.1) = -1 f(0.0) = 0 ``` (The `Math.ceil()` function always rounds up, so `Math.ceil(-0.1) = 0`

Original source