Method Deck / finance

Tip and split a bill

Computes the tip amount, the total bill, and each person's even share when a bill is split among a number of people.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Convert the tip percent to a decimal: t = tip_percent / 100.
  2. tip_amount = bill_amount * t.
  3. total_amount = bill_amount + tip_amount.
  4. amount_per_person = total_amount / number_of_people.
  5. Round tip_amount, total_amount, and amount_per_person to 2 decimals (money to cents).

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"bill_amount":84.5,"tip_percent":18,"number_of_people":4}Tip $15.21, total $99.71, $24.93 per person
test vector: single diner, no tip{"bill_amount":20,"tip_percent":0,"number_of_people":1}Tip $0.00, total $20.00, $20.00 per person

Published card