posted 6 years ago
When a value's decimal part is exactly 0.5, it's rounded up (as specified in the Javadoc comments). For negative numbers this means towards 0. For positive numbers this means away from 0.
SCJP 1.4  SCJP 6  SCWCD 5  OCEEJBD 6  OCEJPAD 6
How To Ask Questions How To Answer Questions
posted 6 years ago
It isn’t at all clear in the Javadoc comments. If you find the Java6 version, it saysRob Spoor wrote: . . . as specified in the Javadoc comments . . .
. . . but the Java7 version saysReturns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression:
(long)Math.floor(a + 0.5d)
I think the old version was much easier to understand.with ties rounding up.
posted 6 years ago
directly from the API:
round:
Returns the closest long to the argument.
Floor:
Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer
saahil gupta wrote:What is the Major difference between Math.Round and Math.Floor Functions?
directly from the API:
round:
Returns the closest long to the argument.
Floor:
Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
posted 6 years ago
I think the new version is much easier to understand; moreover the old version is decidedly too much information. Documentation should tell me in no uncertain terms what result I will get, to be sure; but it should not lay bare the procedure employed to reach that result.
Campbell Ritchie wrote:I think the old version was much easier to understand.
I think the new version is much easier to understand; moreover the old version is decidedly too much information. Documentation should tell me in no uncertain terms what result I will get, to be sure; but it should not lay bare the procedure employed to reach that result.
Evil is afoot. But this tiny ad is just an ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
