>>> round(123,-2)
100.0
>>>
Come arrotondarlo a 100 anziché 100.0? Python: come arrotondare 123 a 100 anziché 100.0?
>>> round(123,-2)
100.0
>>>
Come arrotondarlo a 100 anziché 100.0? Python: come arrotondare 123 a 100 anziché 100.0?
int(round(123,-2))
Il int function può essere utilizzato per convertire una stringa o numero in un intero semplice.
si può semplicemente buttare in int
:
In [1]: int(round(123, -2))
Out[1]: 100
si potrebbe usare int(100.0)
convertire in 100
in Python 2.x ed in python3.x, il suo solo funziona
Python 3.1.2 (r312:79149, ...
>>>
>>> round(123,-2)
100
>>>
Puoi usa l'espressione regolare: (\ d +) \ .. * per far corrispondere l'intera cosa ed estrai solo la parte intera.