|  | 
 
 发表于 2019-9-27 09:49:28
|
显示全部楼层 
| 本帖最后由 xjtu_wong 于 2019-9-27 10:11 编辑 
 复制代码class Float_2_ASCII_dec():
    def __init__(self,float_in):
        self.float_in = float_in
    def invert_2_list(self):
        float_in_list = list(str(self.float_in))
        float_in_list_out = [0,0,0,0,0,0]
        for index in range(min(len(float_in_list),6)):
            float_in_list_out[index] = float_in_list[index]
        return float_in_list_out[0:6]
    def invert_2_ascii(self):
        float_in_list = Float_2_ASCII_dec.invert_2_list(self)
        print(float_in_list)
        float_in_str = str(float_in_list).replace('.','46')
        return float_in_str
复制代码if __name__ == "__main__":
    f2d_1 = Float_2_ASCII_dec(0.1)
    print(f2d_1.invert_2_ascii())
    f2d_2 = Float_2_ASCII_dec(0.12345678)
    print(f2d_2.invert_2_ascii())
复制代码>>>
['0', '.', '1', 0, 0, 0]
['0', '46', '1', 0, 0, 0]
['0', '.', '1', '2', '3', '4']
['0', '46', '1', '2', '3', '4']
最后转换成整数形式应该就可以了
 
 | 
 |