Function ethers::core::utils::format_units[][src]

pub fn format_units<T, K>(amount: T, units: K) -> String where
    T: Into<U256>,
    K: Into<Units>, 
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");