mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-24 02:27:08 -06:00
Merge pull request #1036 from Silvertree2010/fix/h639-number-format-thousands-scaling
This commit is contained in:
@@ -253,7 +253,7 @@ fn fixed(toks: &[Tok], first: usize, last: usize, v: f64, sep: char, dec: char)
|
||||
let grouping = int_part.iter().any(|t| *t == Tok::Comma || matches!(t, Tok::Lit(s) if s.trim().is_empty()));
|
||||
// Commas right after the last digit scale by a thousand each (`#,##0,` = thousands).
|
||||
let after = toks.get(last + 1..).unwrap_or(&[]);
|
||||
let scale_commas = if dot.is_none() { after.iter().take_while(|t| **t == Tok::Comma).count() } else { 0 };
|
||||
let scale_commas = after.iter().take_while(|t| **t == Tok::Comma).count();
|
||||
let min_int = int_part.iter().filter(|t| **t == Tok::Digit('0')).count();
|
||||
let frac_digits: Vec<char> = frac_part.iter().filter_map(|t| if let Tok::Digit(c) = t { Some(*c) } else { None }).collect();
|
||||
let max_frac = frac_digits.len();
|
||||
@@ -314,6 +314,12 @@ mod tests {
|
||||
assert_eq!(format("\"x\"0", 5.0, None), "x5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_commas_with_decimals() {
|
||||
assert_eq!(format("0.0,,", 15_000_000.0, Some("en-US")), "15.0");
|
||||
assert_eq!(format("0.00,\"K\"", 15_000.0, Some("en-US")), "15.00K");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scientific_formats() {
|
||||
assert_eq!(format("0.00E+00", 1234.0, None), "1.23E+03");
|
||||
|
||||
Reference in New Issue
Block a user