Skip to content
Snippets Groups Projects
Commit 8f67e583 authored by Nicolas80's avatar Nicolas80 Committed by Hugo Trentesaux
Browse files

Fixing precision issue when converting the u64 cents amount into f32. (!39)

* Fixing precision issue when converting the u64 cents amount into f32.
Now composing the displayed value with integer part and fractional part separately (keeping left padding of 0 for the decimal part for the amount of decimals required)
parent a11ca34f
No related branches found
No related tags found
1 merge request!39Fixing precision issue when converting the u64 cents amount into f32.
......@@ -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 ---
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment