Skip to content

A menu asking for 2.5 servings puts 3 servings' worth on the shopping list #680

Closed

Description

@LeMyst

A menu line asking for a number of servings that is not whole puts the wrong amount on the shopping list: the servings are rounded first.

Reproduce

stew.cook:

---
servings: 1
---

Simmer @beans{100%g}.

week.menu:

== Monday (2026-10-05) ==

Dinner: \
- @./stew{2.5%servings}
Menu line cook shopping-list week.menu expected
@./stew{2%servings} beans 200 g 200 g
@./stew{2.5%servings} beans 300 g 250 g
@./stew{2 1/2%servings} beans 300 g 250 g

The server does the same: Add All to Shopping List on that menu adds 300 g of beans. The menu page itself shows the line at ×2.5 and links to /recipe/stew?servings=2.5, so the page and its shopping list disagree.

Plans make this common. The calendar writes whatever number of servings is typed (@./Risotto{2.5%servings}, or 2 1/2 once #677 lands), and half servings are a normal thing to plan.

Cause

Recipe references with a servings target are scaled with cooklang's Recipe::scale_to_target (crates/core/src/shopping_list/mod.rs:995). For servings it rounds the target to a whole number before scaling:

// cooklang 0.19.0, src/scale.rs:128-131
Some("servings") | Some("serving") => {
    // Scale by servings - convert f64 to u32
    let servings = target_value.round() as u32;
    self.scale_to_servings(servings, converter)
}

The shopping list has used scale_to_target for references since d46b166 ("feat: cook doctor", 2025-08-21). a69b461 ("fix(shopping-list): follow recipe references all the way down") then mirrored the rounding in target_factor (target.round() / base), so recipes referenced further down scale the same wrong way.

Fix

Scale by target / servings in CookCLI when the target is in servings and the recipe has a number of servings. Leave the other cases (yield, no unit, no servings) to scale_to_target, so its errors stay as they are. Draft PR to follow.

The rounding itself is in cooklang-rs; issue filed there too.

Activity

  1. added
    bug
    area: shopping-list
    on Oct 11, 2026
  2. LeMyst commented on Oct 11, 2026

    @LeMyst
    CollaboratorAuthor

    Filed upstream as cooklang/cooklang-rs#133.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: shopping-listbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions