From 7269b12f1e9fbc954fc56db9941f3b863d921e44 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 22 Oct 2026 02:36:05 +0000 Subject: [PATCH] Integration: #1976 scenarioShow writes stored numbers as values Entering them through the parser applied percent entry to Percentage-formatted cells (a stored 0.05 would not round-trip). Test: scenario_show_restores_a_percentage_cells_stored_number. --- crates/engine/src/cmd/whatif.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/whatif.rs b/crates/engine/src/cmd/whatif.rs index 09c716cab..8e412fee7 100644 --- a/crates/engine/src/cmd/whatif.rs +++ b/crates/engine/src/cmd/whatif.rs @@ -488,8 +488,15 @@ fn scenario_show(s: &mut Session, p: &Json) -> Result { let (_, cells) = cell_list(&d.wb, &sc.changing, CMD, MAX_SCENARIO_CELLS)?; edit(s, |cx| { for (c, v) in cells.iter().zip(sc.values.iter()) { - let input = super::edit::json_to_input(v); - let cell = super::edit::input_to_cell(&input, si, *c, &mut cx.wb)?; + // Stored numbers are values, not typed text: entering them through the parser would + // apply percent entry (9 -> 9%) to a Percentage-formatted cell. + let cell = match v.as_f64() { + Some(n) => { + let style = cx.wb.sheet(si).map(|sh| sh.style_id(*c)).unwrap_or_default(); + Some(Cell { value: Value::Number(n), formula: None, style }) + } + None => super::edit::input_to_cell(&super::edit::json_to_input(v), si, *c, &mut cx.wb)?, + }; let sh = cx.sheet_mut(si)?; match cell { Some(cell) => sh.set_cell(*c, cell), @@ -1199,6 +1206,17 @@ mod tests { assert!(!r.converged); } + #[test] + fn scenario_show_restores_a_percentage_cells_stored_number() { + let mut s = s(); + s.execute("home.numberFormat", json!({"range": "B2", "format": "Percentage"})).unwrap(); + s.execute("cell.set", json!({"cell": "B2", "input": "5"})).unwrap(); + s.execute("data.scenarioAdd", json!({"name": "Low", "changing": "B2"})).unwrap(); + s.execute("cell.set", json!({"cell": "B2", "input": "9"})).unwrap(); + s.execute("data.scenarioShow", json!({"name": "Low"})).unwrap(); + assert_eq!(n(&s, "B2"), 0.05); + } + #[test] fn scenarios() { let mut s = s();