Question 4
Back to Exercise
A bill of ₹2.675 should be rounded half up to ₹2.68. Which statement correctly identifies the bug?
amount = 2.675
print(round(amount, 2))
- A The float 2.675 is really 2.67499…, and round() also rounds halves to even; use decimal.Decimal("2.675").quantize(Decimal("0.01"), ROUND_HALF_UP) Correct
- B round() only rounds to whole numbers
- C The second argument is the number of significant figures
- D print truncates floats
Correct Answer: Option A
For money, use Decimal built from strings with an explicit rounding mode.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!