Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pad_end function does not accept the 0 position #5319

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions utils/fixed_decimal/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ impl FixedDecimal {
self
}

/// Pads this number with trailing zeros on a particular (negative) position. Will truncate
/// Pads this number with trailing zeros on a particular (non-positive) position. Will truncate
/// trailing zeros if necessary, but will not truncate other digits.
///
/// Positive numbers have no effect.
Expand All @@ -1133,20 +1133,19 @@ impl FixedDecimal {
/// let mut dec = FixedDecimal::from_str("123.456").unwrap();
/// assert_eq!("123.456", dec.to_string());
///
/// dec.pad_end(-1);
/// assert_eq!("123.456", dec.to_string());
///
/// dec.pad_end(-2);
/// assert_eq!("123.456", dec.to_string());
///
/// dec.pad_end(-6);
/// assert_eq!("123.456000", dec.to_string());
///
/// dec.pad_end(-4);
/// assert_eq!("123.4560", dec.to_string());
/// let mut dec = FixedDecimal::from_str("123.000").unwrap();
/// dec.pad_end(0);
/// assert_eq!("123", dec.to_string());
///
/// ```
pub fn pad_end(&mut self, position: i16) {
if position >= 0 {
if position > 0 {
return;
}
let bottom_magnitude = self.nonzero_magnitude_end();
Expand Down