判断是否为保留两位小数的数字
def check_money_interface(money):
# 支付时,输入的金额可能是小数,也可能是整数
s = str(money)
if s.count('.') == 1: # 判断小数点个数
sl = s.split('.') # 按照小数点进行分割
left = sl[0] # 小数点前面的
right = sl[1] # 小数点后面的
count_right = 0
for num in right:
count_right += 1
if 2 >= count_right > 0: # 判断小数位数是否小于等于2
if left.startswith('-') and left.count('-') == 1 and right.isdigit():
lleft = left.split('-')[1] # 按照-分割,然后取负号后面的数字
if lleft.isdigit():
return False
elif left.isdigit() and right.isdigit():
# 判断是否为正小数
return True
else:
return False
elif s.isdigit():
s = int(s)
if s != 0:
return True
return False