Skip to content

Commit

Permalink
Breaking: change format_fixed_decimal to accept a reference to `Signe…
Browse files Browse the repository at this point in the history
…dFixedDecimal` (unicode-org#5882)
  • Loading branch information
younies authored Dec 9, 2024
1 parent e7c271a commit 9e5a25b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions components/experimental/src/compactdecimal/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl CompactDecimalFormatter {
/// ```
pub fn format_i64(&self, value: i64) -> FormattedCompactDecimal<'_> {
let unrounded = SignedFixedDecimal::from(value);
self.format_fixed_decimal(unrounded)
self.format_fixed_decimal(&unrounded)
}

/// Formats a floating-point number in compact decimal notation using the default
Expand Down Expand Up @@ -380,7 +380,7 @@ impl CompactDecimalFormatter {
// NOTE: This first gets the shortest representation of the f64, which
// manifests as double rounding.
let partly_rounded = SignedFixedDecimal::try_from_f64(value, RoundTrip)?;
Ok(self.format_fixed_decimal(partly_rounded))
Ok(self.format_fixed_decimal(&partly_rounded))
}

/// Formats a [`SignedFixedDecimal`] by automatically scaling and rounding it.
Expand All @@ -406,38 +406,38 @@ impl CompactDecimalFormatter {
/// .unwrap();
///
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(0)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(0)),
/// "0"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(2)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(2)),
/// "2"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(843)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(843)),
/// "843"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(2207)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(2207)),
/// "2.2K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(15127)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(15127)),
/// "15K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(3010349)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(3010349)),
/// "3M"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(SignedFixedDecimal::from(-13132)),
/// short_english.format_fixed_decimal(&SignedFixedDecimal::from(-13132)),
/// "-13K"
/// );
///
/// // The sign display on the FixedDecimal is respected:
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal(
/// SignedFixedDecimal::from(2500)
/// &SignedFixedDecimal::from(2500)
/// .with_sign_display(fixed_decimal::SignDisplay::ExceptZero)
/// ),
/// "+2.5K"
Expand All @@ -457,31 +457,31 @@ impl CompactDecimalFormatter {
/// # Default::default(),
/// # ).unwrap();
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("999499.99".parse().unwrap()),
/// short_english.format_fixed_decimal(&"999499.99".parse().unwrap()),
/// "999K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("999500.00".parse().unwrap()),
/// short_english.format_fixed_decimal(&"999500.00".parse().unwrap()),
/// "1M"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("1650".parse().unwrap()),
/// short_english.format_fixed_decimal(&"1650".parse().unwrap()),
/// "1.6K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("1750".parse().unwrap()),
/// short_english.format_fixed_decimal(&"1750".parse().unwrap()),
/// "1.8K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("1950".parse().unwrap()),
/// short_english.format_fixed_decimal(&"1950".parse().unwrap()),
/// "2K"
/// );
/// assert_writeable_eq!(
/// short_english.format_fixed_decimal("-1172700".parse().unwrap()),
/// short_english.format_fixed_decimal(&"-1172700".parse().unwrap()),
/// "-1.2M"
/// );
/// ```
pub fn format_fixed_decimal(&self, value: SignedFixedDecimal) -> FormattedCompactDecimal<'_> {
pub fn format_fixed_decimal(&self, value: &SignedFixedDecimal) -> FormattedCompactDecimal<'_> {
let log10_type = value.absolute.nonzero_magnitude_start();
let (mut plural_map, mut exponent) = self.plural_map_and_exponent_for_magnitude(log10_type);
let mut significand = value.clone();
Expand Down

0 comments on commit 9e5a25b

Please sign in to comment.