If I get a token's decimal, and a BigUInt balance, how to format it to a string? THX!
Activity
dangell7 commentedon Dec 4, 2020
AlleniCode commentedon Dec 7, 2020
My test code:
@dangell7 Is this right?
dangell7 commentedon Dec 7, 2020
Is this after calling getBalance?
Or are you creating variables for interaction with a smart contract?
AlleniCode commentedon Dec 8, 2020
@dangell7 Yes. The 'big' constant with type 'BigUInt' is the balance I got from a samrt contract.
Some code here:
RaviRanjan-11 commentedon Jan 1, 2021
You can use your own unit using web3Units
create Your Unit
let myUnit = Web3Units(rawValue: your deciamal Unit)
Fetch balance with web3 instance and your address
let balance = try? wInstance.eth.getBalance(address: yourEthAddress)
convert balance in to string
let balanceString = Web3.Utils.formatToEthereumUnits(balance ?? "0", toUnits: myUnit, decimals: 4)
Iysbaera commentedon Jun 29, 2021
@AlleniCode Hey, do you still have this issue?