Prompt
Write a Python function `round_half_up(x, ndigits=0)` that rounds `x` to `ndigits` decimal
places, rounding halves **away from zero** — so `2.5` → `3` and `-2.5` → `-3`. This is *not*
Python's built-in `round`, which uses banker's rounding (round-half-to-even) and is also
subject to binary-float representation error.
Return a float. Examples:
- `round_half_up(0.5)` → `1.0`
- `round_half_up(2.5)` → `3.0`
- `round_half_up(-1.5)` → `-2.0`
- `round_half_up(3.14159, 2)` → `3.14`
- `round_half_up(2.675, 2)` → `2.68`
Put it in a single Python code block. It will be imported as `from solution import round_half_up`.when to use it
Community prompt sourced from the open-source GitHub repo Green-PT/honey-for-devs (MIT). A "Prompt" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
codingcommunitydeveloper
source
Green-PT/honey-for-devs · MIT
more in Coding
Coding✓ tested
Senior code review (strict mode)
senior staff engineer running a merciless but fair review
Coding✓ tested
Debug by hypothesis, not by guessing
debugging partner who forms theories before touching code
Coding✓ tested
Generate tests from described behavior
test engineer who writes tests that would actually catch regressions