FA-96899 / Recipe scaling and nutrition / Member archive
Nutrition label rounding: half-up tie rounding · case 04
A 47.5 kcal serving prints 50 but 42.5 kcal prints 40, and 142.5 mg sodium flips between bands.
Case contract
Round a panel dict to displayed strings (toy label rules, half-up): calories <5 -> 0, <=50 -> nearest 5, else nearest 10; fat g <0.5 -> 0, <5 -> nearest 0.5, else nearest 1; sodium mg <5 -> 0, <=140 -> nearest 5, else nearest 10; cholesterol mg <2 -> "0 mg", <5 -> "less than 5 mg", else nearest 5; carbs g <0.5 -> "0 g", <1 -> "less than 1 g", else nearest 1. Absent keys are omitted. Values print with %g formatting.
Why this case matters
Packaged food and meal-kit labels are generated from recipe nutrition totals with banded rounding rules that differ per nutrient.
One recorded failure
Sample boundary fixtureThis sample comes from the broken implementation of a controlled reproducer.
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| large values | {"calories": "240", "cholesterol": "20 mg", "fat": "12 g", "sodium": "460 mg"} | {"calories": "250", "cholesterol": "25 mg", "fat": "13 g", "sodium": "460 mg"} | Failed |
MEMBER ARCHIVE
The complete case is available to members.
This record includes three runnable implementations, regression fixtures, execution results, and source hashes.
Member access is invitation-based. Sign in with your invited account to inspect the sources.
Sign in to the archive ↗