7//5 gives | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
30th Sep 2018, 8:08 AM
rafeek
rafeek - avatar
19 Respostas
+ 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šŸ˜†
30th Sep 2018, 7:18 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 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
30th Sep 2018, 6:57 PM
Flandre Scarlet
Flandre Scarlet - avatar
30th Sep 2018, 7:04 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 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šŸ˜‚
30th Sep 2018, 7:08 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 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 šŸ˜†
30th Sep 2018, 7:11 PM
Anna
Anna - avatar
+ 2
python gives 1; js/java/c/c++/c# gives 7šŸ˜€
30th Sep 2018, 11:10 AM
Flandre Scarlet
Flandre Scarlet - avatar
+ 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?
30th Sep 2018, 6:42 PM
Anna
Anna - avatar
+ 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!
30th Sep 2018, 6:58 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
"On most computer implementations, the selected rule is to round half-integers to the nearestĀ even integer" šŸ˜³
30th Sep 2018, 7:08 PM
Anna
Anna - avatar
+ 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
30th Sep 2018, 8:34 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 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
30th Sep 2018, 7:00 PM
Anna
Anna - avatar
+ 1
That actually makes sense. č°¢č°¢ä½ 
30th Sep 2018, 7:23 PM
Anna
Anna - avatar
+ 1
Kishalaya Saha next problem: how to decide the "random" which is really randomšŸ˜‚
30th Sep 2018, 7:43 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 1
rafeek 7//5 = 1. Please see the first comment (sort the posts by date)
4th Oct 2018, 3:57 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
thank you now i undstd...
4th Oct 2018, 4:10 PM
rafeek
rafeek - avatar
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.
30th Sep 2018, 7:41 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
7//5=??
4th Oct 2018, 3:54 PM
rafeek
rafeek - avatar
0
heyy please can you explain.How it become 1. i dint undstd first comment. please can you explain.
4th Oct 2018, 3:59 PM
rafeek
rafeek - avatar
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
4th Oct 2018, 4:07 PM
Kishalaya Saha
Kishalaya Saha - avatar