decimal place fix in checking balance and sending usdt
This commit is contained in:
parent
a1f3953db8
commit
92f42cfabc
@ -304,14 +304,20 @@
|
|||||||
let balance = await contract.balanceOf(address);
|
let balance = await contract.balanceOf(address);
|
||||||
|
|
||||||
// Assuming 18 decimals for most tokens like USDT and USDC
|
// Assuming 18 decimals for most tokens like USDT and USDC
|
||||||
const decimals = 0;
|
// const decimals = 0.00;
|
||||||
balance = parseFloat(ethers.utils.formatUnits(balance, decimals));
|
const decimals = 18;
|
||||||
|
const formattedDecimals = decimals.toFixed(1); // This will convert 18 to "18.00"
|
||||||
|
console.log(formattedDecimals); // Outputs: "18.0"
|
||||||
|
|
||||||
// Format the balance to 2 decimal places for display
|
balance = parseFloat(ethers.utils.formatUnits(balance, decimals));
|
||||||
balance = balance.toFixed(2);
|
|
||||||
|
|
||||||
return balance;
|
// Format the balance to 2 decimal places for display
|
||||||
} catch (e) {
|
balance = balance.toFixed(2);
|
||||||
|
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (e) {
|
||||||
console.error("Error getting token balance:", e.message);
|
console.error("Error getting token balance:", e.message);
|
||||||
throw new Error("Failed to get token balance");
|
throw new Error("Failed to get token balance");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user