|
|
Re: Discrepancy in Rounding the numbers
|
Posted: Aug 16, 2006 12:29 AM
|
|
> In Java, > Math.round(1.5) gives the output as 2 > Math.round(-1.5) gives the output as -1 > > In Oracle, > select round(1.5) from dual gives the output as 2 > select round(-1.5) from dual gives the output as 2 > > If you look the outputs in both the platforms, positive > rounding works fine as expected. But not the negative > rounding.
Neither is inconsistant. Java consistantly rounds up (i.e. more positive), whilst Oracle consistantly rounds away from zero. Both are equally correct. Rounding to the nearest even value is also a valid option (used most frequently in financial systems).
From a pure mathmatical viewpoint there is nothing to choose between rounding 1.5 up or down to the nearest integer. Therefore, there is no 'correct' way and thus no reason to say that one works 'as expected' and one doesn't.
V.
|
|