Rounding of .5 not rounding upwards

Rounding of .5 not rounding upwards - Rounding of .5 not rounding upwards - 消息

#1 已发布: 2021/3/10 20:27:07
bugreportaccount

bugreportaccount

0个赞,共4个帖子。

组: User

With rounding selected as half to even, the rounding doesn't round .5 up to 1.

For example, with decimal places set to 0:
2.50000 = 2
2.50001 = 3

This doesn't seem in line with the expectation that .5 rounds upwards and leaves some of my calculations looking misrepresentative on inspection. Same with the round function, which leaves something like 2.5 becoming 2, not 3.

Or is this intentional?

Thanks,
#2 已发布: 2021/3/10 20:46:04
overlord

overlord

600个赞,共1,381个帖子。

组: Moderator

This is intentional.
Please pay attention to description.
Half to even, it is rounding to even number.
Even numbers are 2,4,6,8...
Odd numbers are 1,3,5,7...

If decimal part of number is even then it round downward to its base.
If decimal part of number is odd, it round upwards.
If you want always round to up when fraction is equal or bigger than .5;
You have to use away from zero rounding option.

https://en.wikipedia.org/wiki/Rounding#Round_half_to_even

Regards

2021-03-11_02-39.png
#3 已发布: 2021/3/10 21:44:42
overlord

overlord

600个赞,共1,381个帖子。

组: Moderator

Wrote

Same with the round function, which leaves something like 2.5 becoming 2, not 3.


round() function when used with two parameters always do rounding with half to even.
If you want away from zero option in round() function, add third parameter and make it 1.

Regards.

2021-03-11_03-44.png
#4 已发布: 2021/3/11 03:09:08
bugreportaccount

bugreportaccount

0个赞,共4个帖子。

组: User

I see, that does make sense now, appreciate the responses, especially the solution from overlord
#5 已发布: 2021/3/11 09:01:00
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

Wrote

Same with the round function, which leaves something like 2.5 becoming 2, not 3.


round.PNG


  • 有新帖
  • 无新帖