Advertisement
Kyrexar

Recorta decimales

May 8th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: latin-1 -*-
  3. import os, sys
  4.  
  5. def imp2dec(num):
  6.     partentera=int(num)
  7.     decimal1=int((num-partentera)*10)
  8.     decimal2=int((num-partentera)*100)-(decimal1*10)
  9.     decimal3=int((num-partentera)*1000)-(decimal1*100+decimal2*10)
  10.     if decimal3>=5 and decimal2!=9 : decimal2+=1 # Redondeo
  11.     print(str(partentera)+"."+str(decimal1)+str(decimal2))
  12.  
  13. while bool!=0 :
  14.     bool=input("Introduce un numero: ")
  15.     imp2dec(bool)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement