floor() versus int()

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

floor() versus int()

Message par compsystems » mar. avr. 30, 2019 10:10 pm

Hello BP,

It seems that int() and floor() python syntax are doing the same, I think it's better to separate in two different functions.

According to python languaje

floor() rounds down, int() truncates. The difference is clear when you use negative numbers:

» import math
» math.floor(-3.5)
-4
» int(-3.5)
-3
Rounding down on negative numbers means that they move away from 0, truncating moves them closer to 0.

Putting it differently, the floor() is always going to be lower or equal to the original. int() is going to be closer to zero or equal
.

Répondre