Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 21, 2020 17:02
Show Gist options
  • Save rust-play/f90dcbbe98446d8aaabdfe128e09cf2a to your computer and use it in GitHub Desktop.
Save rust-play/f90dcbbe98446d8aaabdfe128e09cf2a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
pub fn fmt_value_in(&self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result {
let sats = self.as_sat().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| {
// We could also hard code this into `2147483648`
u64::max_value() - self.as_sat() as u64 +1
});
fmt_satoshi_in(sats, self.is_negative(), f, denom)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment