二进制小数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# -*- coding:utf-8 -*-
class BinDecimal:
    def printBin(self, num):
        aa = num*2
        rest = []
        rest.append(str(int(aa)))
        while aa != 1:
            aa = (aa - int(aa))*2
            rest.append(str(int(aa)))
        res = '0.' + "".join(rest)
        if len(res)>= 32: 
            return "Error"
        return res
aa = BinDecimal()
print aa.printBin(0.46502)