0
7//5 gives
19 Antworten
+ 4
i read the nearest integer function in Chinese Wiki and found it's also called "Banker's Rounding"
it says if we round up all .5, the average result becomes too large, so we round up .5 when its integer part is odd, and round down when it's even
it makes sense, especially for banks😆
+ 3
Anna actually, that's totally correct
for round(number), [.0, .5) are ignored, (.5, 1.0) become 1
and for exactly .5, the closest even interger is taken as the round
that's why round(11.5)=round(12.5)=12
+ 3
+ 3
Anna before in university i also learned that, but in university, all values in science are measured and rounded with precision but not simple >=.5
and actually, there's seldom an exact .5, it usually appears when calculating the average of some data
I'm not sure why it's ruled to round .5 to even numbers, maybe our professor had said about it but i forgot it😂
+ 3
Flandre Scarlet Hmm, okay. I had no idea. I'll definitely write that in my "Today I learned" book. Thanks and sorry for hijacking this thread 😆
+ 2
python gives 1;
js/java/c/c++/c# gives 7😀
+ 2
Kishalaya Saha, this is totally off-topic, but did you know that python doesn't round .5 mathematically correct to the next largest integer, but to the next even integer? So 11.5 will be rounded up to 12, but 12.5 will be rounded down to 12? How weird is that?
+ 2
Anna It is weird! I had to do the same in my numerical analysis course in college. Our teacher told us that it's because rounding up everytime would increase the mean. Or something of that sort.
When asked why even, and not odd, he said it's because we'd often have to divide by 2, so it would be convenient that way. Silly, I know!
+ 2
"On most computer implementations, the selected rule is to round half-integers to the nearest even integer" 😳
+ 1
// is called the floor division operator. Dividing 7 by 5 we get 1.4. The integer closest to 1.4, but smaller than it is 1. So 7//5 is 1.
See the second page here:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2273/?ref=app
+ 1
Flandre Scarlet Really? I've never heard of that before. I've always learned that anything >= .5 is rounded up no matter what 🤔
/Edit: C(++) rounds 2.5 to 3
+ 1
That actually makes sense. 谢谢你
+ 1
Kishalaya Saha next problem: how to decide the "random" which is really random😂
+ 1
rafeek
7//5 = 1.
Please see the first comment (sort the posts by date)
+ 1
thank you now i undstd...
0
I vote for random rounding: 1.5 will be rounded to 2 with probability 50% and to 1 with probability 50%. No bias towards the even numbers!
I know, I know, it'd be a slower process, and we'd lose some consistency.
0
7//5=??
0
heyy please can you explain.How it become 1.
i dint undstd first comment. please can you explain.
0
Let's see... First divide 7 by 5 the regular way. The result is 1.4. But what if we want our result as an integer? This is one way of doing it: 1.4 lies between 1 and 2. The operator // gives the smaller of these two integers, which is 1 in this case. So
7//5 = 1.
This is called the floor division, because there's also a floor function in math/computing, that does exactly that
floor(1.4) = 1
floor(3.97) = 3
floor(-3.2) = -4 (Note this one carefully)
Aside: There's also a ceiling function, that finds the integer bigger than the input number. So ceiling(1.4)=2