Momo Bill Catculator
Momo will help you split the bill if you let her know how much human things cost
total = 0
tip = 0
discount = 0
tax = 0
cost = 0
def calc_tips(*args, **kwargs):
global total
total = document.getElementById('i_total')
total = float(total.value)
tip_15_perc = round(total * 0.15, 2)
tip_17_perc = round(total * 0.17, 2)
tip_20_perc = round(total * 0.20, 2)
log_tips = document.getElementById('field_tips')
log_tips.innerHTML = '15% tip = $' + '{0:.2f}'.format(tip_15_perc) + '\n 17% tip = $' + '{0:.2f}'.format(tip_17_perc) + '\n 20% tip = $' + '{0:.2f}'.format(tip_20_perc)
document.getElementById('div_tip').style.display = 'block'
document.getElementById('progress').value = 20
def calc_total_w_tip(*args, **kwargs):
global total, total_w_tip, tip
tip = document.getElementById('i_tip')
tip = float(tip.value)
tip_perc = round(tip / total * 100, 2)
total_w_tip = round(total + tip, 2)
log_total_w_tip = document.getElementById('field_total_w_tip')
log_total_w_tip.innerHTML = 'Total + tip = $' + '{0:.2f}'.format(total_w_tip) + ' (' + '{0:.1f}'.format(tip_perc) + '% tip)'
document.getElementById('div_discount').style.display = 'block'
document.getElementById('progress').value = 40
def calc_total_w_tip_discount(*args, **kwargs):
global total, total_w_tip, tip, total_w_tip, discount
discount = document.getElementById('i_discount')
discount = float(discount.value)
total_w_tip_discount = round(total_w_tip - discount, 2)
log_total_w_tip_discount = document.getElementById('field_total_w_tip_discount')
log_total_w_tip_discount.innerHTML = 'Total + tip - discount = $' + '{0:.2f}'.format(total_w_tip_discount)
document.getElementById('div_tax').style.display = 'block'
document.getElementById('progress').value = 60
def calc_total_w_tip_discount_tax(*args, **kwargs):
global total, total_w_tip, tip, total_w_tip, discount, tax
tax = document.getElementById('i_tax')
tax = float(tax.value)
total_w_tip_discount_tax = round((total - discount) * (tax / 100 + 1) + tip, 2)
log_total_w_tip_discount_tax = document.getElementById('field_total_w_tip_discount_tax')
log_total_w_tip_discount_tax.innerHTML = 'Total + tip - discount + tax = $' + '{0:.2f}'.format(total_w_tip_discount_tax)
document.getElementById('div_cost').style.display = 'block'
document.getElementById('progress').value = 80
def calc_cost(*args, **kwargs):
global total, total_w_tip, tip, total_w_tip, discount, tax, cost
cost = document.getElementById('i_cost')
cost = float(safe_math_eval(cost.value))
total_w_discount_tax = (total - discount) * (tax / 100 + 1)
cost_w_discount_tax = cost * (total - discount) / total * (tax / 100 + 1)
perc_of_tip = round(cost_w_discount_tax / total_w_discount_tax * 100, 2)
pay = round(cost_w_discount_tax + cost_w_discount_tax / total_w_discount_tax * tip, 2)
log_individual_cost = document.getElementById('individual_cost')
log_individual_cost.innerHTML += '$' + '{0:.2f}'.format(cost) + ' ➡️ $' + '{0:.2f}'.format(pay) + ' (includes ' + '{0:.1f}'.format(perc_of_tip) + '% of tip)\n'
document.getElementById('progress').value = 100
document.getElementById('progress').className = "progress is-success"
def safe_math_eval(string):
allowed_chars = "0123456789+-*(). /"
for char in string:
if char not in allowed_chars:
raise Exception("Unsafe eval")
return eval(string, {"__builtins__": None}, {})