我目前在一个 nft 市场上工作,想在每次销售中收取 2.5% 的费用。我已经阅读并在线搜索了如何计算可靠性百分比并在这方面取得了成功,但问题是它的结果是一个巨大的数字,即 2.5 * 150/100 应该返回 3.75,但我得到了这个数字:3750000000000000000000000000000000000
我的测试
const auctionPrice = ethers.utils.parseUnits("1", "ether");
const [_, userAddress] = await ethers.getSigners();
let fee = (2.5 * auctionPrice) / 100;
const commission = ethers.utils.parseUnits(fee.toString(), "ether");
let commissionValue = commission.toString();
console.log(commission.toString());
console.log(fee);
await market
.connect(userAddress)
.createMarketSale(nftContractAddress, 1, commissionValue, {
value: auctionPrice,
});
结果
250000000000000000000000000000000
1 failing
1) NFTMarket
Should create and execute market sales:
Error: Transaction reverted: function call failed to execute
at NFTMarket.createMarketSale (contracts/NFTMarket.sol:165)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:526:9)
at processTimers (node:internal/timers:500:7)
at HardhatNode._mineBlockWithPendingTxs (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:1602:23)
at HardhatNode.mineBlock (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:435:16)
at EthModule._sendTransactionAndReturnHash (node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:1494:18)
所以我的问题是有没有办法把这个数字(3750000000000000000000000000000000000)变成一个小数或整数?我已经搜索过,但在网上找不到任何关于这个的东西