def data_two_float(data):
data = float(data)
data = str(data)
data_list = data.split('.')
front = data_list[0]
back = data_list[1]
if back == '0':
data = front + '.' + back
data = float(data)
data = '{:,}'.format(data)
data_list = data.split('.')
data_list[1] = '00'
data = '.'.join(data_list)
return data
else:
back_list = list(back)
if len(back_list) > 2:
if int(back_list[2]) > 4:
back_list[1] = str(int(back_list[1]) + 1)
back_list = back_list[0:2]
back = ''.join(back_list)
data = front + '.' + back
data = format(float(data),',')
return data
Python 四舍五入取两位小数,并加千位符
最新推荐文章于 2024-02-18 18:01:36 发布