Skip to content

Commit

Permalink
Merge branch 'brent/fix-dec-display' (#1774)
Browse files Browse the repository at this point in the history
* origin/brent/fix-dec-display:
  changelog: #1774
  fix Display for Dec
  • Loading branch information
Fraccaman committed Aug 11, 2023
2 parents 2cd9ea9 + b36b470 commit d9a151f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/1774-fix-dec-display.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes buggy Display for the Dec type when the number is some multiple of 10
([\#1774](https://github.com/anoma/namada/pull/1774))
10 changes: 9 additions & 1 deletion core/src/types/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ impl Display for Dec {
str_pre.push_str(string.as_str());
string = str_pre;
};
let stripped_string = string.trim_end_matches(['.', '0']);
let stripped_string = string.trim_end_matches('0');
let stripped_string = stripped_string.trim_end_matches('.');
if stripped_string.is_empty() {
f.write_str("0")
} else if is_neg {
Expand Down Expand Up @@ -620,4 +621,11 @@ mod test_dec {
let larger = Dec::from_str("32418116583.390243854642").unwrap();
assert!(smaller < larger);
}

#[test]
fn test_dec_display() {
let num = Dec::from_str("14000.0000").unwrap();
let s = format!("{}", num);
assert_eq!(s, String::from("14000"));
}
}

0 comments on commit d9a151f

Please sign in to comment.