mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
Omit minus sign when FormCalc Format() rounds to zero
Found while testing crates/js/src/formcalc.rs:2328-2330 ("format" number-picture branch, `if num < 0.0 { text = format!("-{text}") }`)
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
aea5e78e66
commit
afcc54fddc
@@ -2325,10 +2325,11 @@ impl Interp<'_> {
|
||||
}
|
||||
text = if frac.is_empty() { g } else { format!("{g}.{frac}") };
|
||||
}
|
||||
let nonzero = text.chars().any(|c| ('1'..='9').contains(&c));
|
||||
if pic.contains('$') {
|
||||
text = format!("${text}");
|
||||
}
|
||||
if num < 0.0 {
|
||||
if num < 0.0 && nonzero {
|
||||
text = format!("-{text}");
|
||||
}
|
||||
Val::Str(text)
|
||||
|
||||
@@ -805,6 +805,14 @@ mod formcalc {
|
||||
o.result.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A negative value that rounds to zero under the picture prints without a minus sign.
|
||||
#[test]
|
||||
fn format_does_not_print_negative_zero() {
|
||||
assert_eq!(calc(r#"Format("9.9", -0.04)"#), "0.0");
|
||||
assert_eq!(calc(r#"Format("99", -0.2)"#), "00");
|
||||
assert_eq!(calc(r#"Format("9.9", -1.5)"#), "-1.5");
|
||||
}
|
||||
|
||||
/// Assigning one long value to many fields at once stops at the run's byte budget and is
|
||||
/// charged per copy, and a reset list names each field once.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user