Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 16, 2019 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/377bdb1e708e46b5279a51240727badf to your computer and use it in GitHub Desktop.
Save parzibyte/377bdb1e708e46b5279a51240727badf to your computer and use it in GitHub Desktop.
"""
3 maneras de redondear números en Python
@author parzibyte
"""
# Si usas ceil y floor importa a math
import math
numero = 1.4
redondeado = round(numero)
redondeado_abajo = math.floor(numero)
redondeado_arriba = math.ceil(numero)
print("Redondeado con round: {}".format(redondeado))
print("Redondeado con floor (hacia abajo): {}".format(redondeado_abajo))
print("Redondeado con ceil (hacia arriba): {}".format(redondeado_arriba))
# Otro ejemplo con round
numero = 1.5
redondeado = round(numero)
print("round(1.5): {}".format(redondeado))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment