Guest User

Untitled

a guest
Oct 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. from math import floor
  2.  
  3.  
  4. def decimal_binary_form(n, limit):
  5. n = n - floor(n)
  6. rep = "0."
  7. sub = 1
  8. pos_count = 0
  9. while n > 0.0 and pos_count != limit:
  10. sub = sub / 2
  11. if n - sub >= 0.0:
  12. rep += '1'
  13. n = n - sub
  14. else:
  15. rep += '0'
  16. pos_count += 1
  17. return rep
  18.  
  19.  
  20. if __name__ == "__main__":
  21. print(decimal_binary_form(1/5, 50))
Add Comment
Please, Sign In to add comment