Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Returning Values

round() vs math.ceil() for total_due

Why not use round(total_due / people, 2) which would return the total rounded to two decimal places instead of ceil() which will round up to the nearest int?

2 Answers

Steven Parker
Steven Parker
210,872 Points

Craig explains this at about 5:15 in the video when he says:

I'm pretty sure that most people don't even have the $0.24 on them. So what happens usually, is whoever is paying the bill ends up paying the extra money for everybody.

So that's why he doesn't round to cents (two places). He then explains the use of "ceil" instead of "round":

The fairest solution that I can think of is to round up to the next dollar. Now note, if we use the round function here it would round down, right, cuz $21.24 will go down to $21. But I'm suggesting that we should pay $22.

Steven, Thanks for the response. Yeah I realized that once I actually ran through it a few times using round(). Even if you get close, your total can end up being off by .01 which is no good for the restaurant. LOL. I appreciate the response.