Implement Python 3's round function in Python 2.7 -
i using old codes written in python 3 in google-app-engine project using python 2.7. different round() algorithms in python 3 , python 2 gives me headache. there convenient way implement python 3's round() method in python 2.7?
a further question: python 2 , python 3 handle integer operations quite differently. example following statements have different outputs in python 2 , 3:
2/4 # 0 in python 2, 0.5 in python 3 round(3/2) math.ceil(0.5) # 1.0 in python 2, 1 in python 3
any easy way convert codes python 3 python 2 while keeping behavior same?
thanks!
banker's rounding implemented in future. float division can made default __future__
import.
from __future__ import division future.modified_builtins import round
Comments
Post a Comment