Skip to content

Commit

Permalink
Fix the padding bug for Uint256 and Uint512
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Sep 2, 2021
1 parent f00fafd commit eb2284f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/std/src/math/uint256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ impl From<Uint256> for String {

impl fmt::Display for Uint256 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
// The inner type doesn't work as expected with padding, so we
// work around that.
let unpadded = self.0.to_string();

f.pad_integral(true, "", &unpadded)
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/std/src/math/uint512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ impl From<Uint512> for String {

impl fmt::Display for Uint512 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
// The inner type doesn't work as expected with padding, so we
// work around that.
let unpadded = self.0.to_string();

f.pad_integral(true, "", &unpadded)
}
}

Expand Down

0 comments on commit eb2284f

Please sign in to comment.