Skip to content
Snippets Groups Projects

Fixing precision issue when converting the u64 cents amount into f32.

Merged Nicolas80 requested to merge Nicolas80/gcli-v2s:fixing_balance_value_formatting into master
1 file
+ 9
4
Compare changes
  • Side-by-side
  • Inline
+ 9
4
@@ -122,11 +122,16 @@ impl Data {
}
// --- methods ---
pub fn format_balance(&self, amount: Balance) -> String {
let base: u32 = 10;
let base: u64 = 10;
let integer_part = amount / base.pow(self.token_decimals);
let fractional_part = amount % base.pow(self.token_decimals);
format!(
"{} {}",
(amount as f32) / (base.pow(self.token_decimals) as f32),
self.token_symbol
"{}.{:0left_padding$} {}",
integer_part,
fractional_part,
self.token_symbol,
left_padding = self.token_decimals as usize
)
}
// --- mutators ---
Loading