0

How does the function floor work ?

21st Dec 2016, 4:49 PM
Hugo
11 Antworten
+ 4
round() rounds to closest int (1.4 = 1, 1.6 = 2)
21st Dec 2016, 4:57 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
you mean floor() method? It rounds numbers towards smaller int. (1.4 = 1, 1.9 = 1)
21st Dec 2016, 4:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
floor(1.259647)
21st Dec 2016, 4:57 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
ceil() to biggest ...
21st Dec 2016, 4:59 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
"floor" follows the mathematical definition for "integer part": it's the largest integer that is smaller than the given value. So watch it! For negative numbers, it's not about dropping the decimal part: from math import floor print(floor(2.4)) # 2 print(floor(-2.4)) # -3
21st Dec 2016, 7:30 PM
Álvaro
+ 2
Is it the same as ' .round() '?
21st Dec 2016, 4:53 PM
iStealApples
iStealApples - avatar
+ 1
If i have 1.259647 for exemple how can i have only 1 ? .floor(1.259647) ?
21st Dec 2016, 4:52 PM
Hugo
+ 1
?
21st Dec 2016, 4:53 PM
Hugo
+ 1
yes but how is the exect way to use it ? floor(x), floor.x , floor"x" ?
21st Dec 2016, 4:55 PM
Hugo
+ 1
i'm just starting to code with python
21st Dec 2016, 4:56 PM
Hugo
+ 1
ok thank you
21st Dec 2016, 4:58 PM
Hugo