Math.round with infinity in java

I am trying to get a valid response for

Math.round(Double.valueOf(1) / Double.valueOf(0))

but I am getting a random number as output. Can someone please help.

Jon Skeet
people
quotationmark

It's behaving exactly as documented - you're not getting "a random number", you're getting Long.MAX_VALUE:

If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.

In your case, the argument is positive infinity. Hence the result.

people

See more on this question at Stackoverflow