7
votes

Python: Comment rond de 123 à 100 au lieu de 100.0?

>>> round(123,-2)
100.0
>>> 
How to round it to 100 instead of 100.0? 

0 commentaires

4 Réponses :


13
votes
int(round(123,-2))
The int function can be used to convert a string or number to a plain integer.

0 commentaires

2
votes

Vous pouvez simplement le jeter dans int : xxx


0 commentaires

1
votes

Vous pouvez utiliser int (100.0) code> pour convertir en 100 code> dans python 2.x et dans python3.x, il fonctionne simplement

Python 3.1.2 (r312:79149, ...
>>>
>>> round(123,-2)
100
>>>


0 commentaires

0
votes

Vous pouvez utiliser une expression régulière: (\ d +) \ .. * Pour correspondre à l'ensemble de la chose et extraire uniquement la partie entière.


0 commentaires