Skip to content

Commit

Permalink
Rename precision to target_scale in format_full_scale
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Oct 27, 2024
1 parent 4ac7de5 commit 65f139a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/impl_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ fn format_full_scale(
zero_right_pad_integer_ascii_digits(&mut digits, &mut exp, f.precision());
} else {
let scale = this.scale as u64;
// no-precision behaves the same as precision matching scale (i.e. no padding or rounding)
let prec = f.precision().and_then(|prec| prec.to_u64()).unwrap_or(scale);

// std::fmt 'precision' has same meaning as bigdecimal 'scale'
//
// interpret 'no-precision' to mean the same as matching the scale
// of the deicmal (i.e. no padding or rounding)
let target_scale = f.precision().and_then(|prec| prec.to_u64()).unwrap_or(scale);

if scale < digits.len() as u64 {
// format both integer and fractional digits (always 'trim' to precision)
format_ascii_digits_with_integer_and_fraction(&mut digits, scale, prec, rounder);
format_ascii_digits_with_integer_and_fraction(&mut digits, scale, target_scale, rounder);
} else {
// format only fractional digits
format_ascii_digits_no_integer(&mut digits, scale, prec, rounder);
format_ascii_digits_no_integer(&mut digits, scale, target_scale, rounder);
}
}

Expand Down

0 comments on commit 65f139a

Please sign in to comment.