From 92f42cfabca4cb302e29e6f1c1673d9f89c7bb54 Mon Sep 17 00:00:00 2001 From: SaketAnand Date: Thu, 5 Sep 2024 18:01:48 +0530 Subject: [PATCH] decimal place fix in checking balance and sending usdt --- scripts/bscOperator.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/bscOperator.js b/scripts/bscOperator.js index e3086b6..4b816c0 100644 --- a/scripts/bscOperator.js +++ b/scripts/bscOperator.js @@ -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"); }