Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import floor
- def decimal_binary_form(n, limit):
- n = n - floor(n)
- rep = "0."
- sub = 1
- pos_count = 0
- while n > 0.0 and pos_count != limit:
- sub = sub / 2
- if n - sub >= 0.0:
- rep += '1'
- n = n - sub
- else:
- rep += '0'
- pos_count += 1
- return rep
- if __name__ == "__main__":
- print(decimal_binary_form(1/5, 50))
Add Comment
Please, Sign In to add comment