Calculate how much each person owes when splitting a bill, including optional tax, tip, fixed-tip precedence, and round-up support.
When the user asks to split a bill:
splitBill with the resolved values.tip_rate and tip_amount are provided, treat tip_amount as the value that takes precedence.round_up is enabled, mention that each share is rounded up to ensure the full bill is covered.splitBill(subtotal, num_people, tax_rate, tip_rate, tip_amount, round_up)Calculates the total bill and each person's share.
subtotal (number): Pre-tax, pre-tip bill amount.num_people (integer): Number of people splitting the bill.tax_rate (number, optional): Tax percentage to apply to the subtotal.tip_rate (number, optional): Tip percentage to apply to the subtotal.tip_amount (number, optional): Fixed tip amount. Takes precedence over tip_rate.round_up (boolean, optional): When true, round each person's share up to the nearest cent.Returns
{
"subtotal": 85.5,
"tax_amount": 7.27,
"tip_amount": 17.1,
"total": 109.87,
"per_person": 36.63,
"num_people": 3
}
subtotal must be greater than 0.num_people must be an integer greater than or equal to 1.tax_rate, tip_rate, and tip_amount must be greater than or equal to 0 when provided.splitBill → scripts/main.js