Rounding negative numbers in Java

后端 未结 6 941
予麋鹿
予麋鹿 2020-12-09 10:30

According to Wikipedia when rounding a negative number, you round the absolute number. So by that reasoning, -3.5 would be rounded to -4. But when I use java.lang.Math.round

6条回答
  •  独厮守ぢ
    2020-12-09 10:39

    Turns out the convention is to round up. I guess Wikipedia is fallible. Turns out Microsoft got it wrong, though, as they round it to -4 as well, which is not convention (I checked with someone who has a PhD in math).

提交回复
热议问题