Function ethers_core::utils::format_units[][src]

pub fn format_units<T: Into<U256>, K: Into<Units>>(
    amount: T,
    units: K
) -> String
Expand description

Divides the provided amount with 10^{units} provided.

use ethers_core::{types::U256, utils::format_units};

let eth = format_units(1395633240123456000_u128, "ether");
assert_eq!(eth.parse::<f64>().unwrap(), 1.395633240123456);

let eth = format_units(U256::from_dec_str("1395633240123456000").unwrap(), "ether");
assert_eq!(eth.parse::<f64>().unwrap(), 1.395633240123456);

let eth = format_units(U256::from_dec_str("1395633240123456789").unwrap(), "ether");
assert_eq!(eth, "1.395633240123456789");