# 把价格拆分成整数+小数点位移值
def price_encode(price):
price_split = str(price).split('.')
price_decimal = 0
if len(price_split) > 1:
price = '%s%s' % (price_split[0], price_split[1])
price_decimal = len(price_split[1].strip())
return int(price), int(price_decimal)
# 把整数和小数点位移值拼接成价格
def price_decode(price, price_decimal):
m = ''
price = list(str(price))
if price_decimal != 0:
if price[0] == '-':
del price[0]
m = '-'
if len(price) <= price_decimal:
for i in range(0, price_decimal - len(price) + 1):
price.insert(0, '0')
price.insert(len(price) - price_decimal, '.')
return m + ''.join(price)
#测试
if __name__ == '__main__':
a