#-*-coding:utf-8-*-
#author:JamesW
class Float2AsciiDec():
def __init__(self,float_in):
self.float_in = float_in
def convert_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 convert_2_ascii(self):
float_in_list = Float2AsciiDec.convert_2_list(self)
float_in_str = []
for each in float_in_list:
if each == '.':
each = 46
float_in_str.append(each)
else:
each = int(each)
float_in_str.append(each)
return float_in_str
if __name__ == "__main__":
f2d_1 = Float2AsciiDec(0.1)
print(f2d_1.convert_2_ascii())
f2d_2 = Float2AsciiDec(0.12345678)
print(f2d_2.convert_2_ascii())
|