1function splitBill(total, people) {
2 const share = total / people;
3 const reconstructed = share * people;
4
5 if (reconstructed !== total) {
6 throw new Error('Split does not add up');
7 }
8 return share;
9}
10
11splitBill(10, 3); // throws: 3.3333... * 3 = 9.999...
no lines flagged
#035PracticeEasy10 min · 50 XP
Floating Point Equality Comparison
A financial calculation comparison returns false for values that should be equal due to floating point precision.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.