Skip to content

Commit

Permalink
decimal place fix in checking balance and sending usdt
Browse files Browse the repository at this point in the history
  • Loading branch information
saketongit committed Sep 5, 2024
1 parent a1f3953 commit 92f42cf
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scripts/bscOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,20 @@
let balance = await contract.balanceOf(address);

// Assuming 18 decimals for most tokens like USDT and USDC
const decimals = 0;
balance = parseFloat(ethers.utils.formatUnits(balance, decimals));

// Format the balance to 2 decimal places for display
balance = balance.toFixed(2);

return balance;
} catch (e) {
// const decimals = 0.00;
const decimals = 18;
const formattedDecimals = decimals.toFixed(1); // This will convert 18 to "18.00"
console.log(formattedDecimals); // Outputs: "18.0"

balance = parseFloat(ethers.utils.formatUnits(balance, decimals));

// Format the balance to 2 decimal places for display
balance = balance.toFixed(2);

return balance;
}

catch (e) {
console.error("Error getting token balance:", e.message);
throw new Error("Failed to get token balance");
}
Expand Down

0 comments on commit 92f42cf

Please sign in to comment.