How to convert Wei to Ether

createItemClick = async () => {

    if (fileInput.files.length == 0) {
        alert("Please select a file!");
        return;
    } else if (itemName.value.length == 0) {
        alert("Please give the item a name!");
        return;
    } else if (itemPrice.value.length == 0) {
        alert("Please give the item price!");
        return;
    } else if (itemDescription.value.length == 0) {
        alert("Please give the item description!");
        return;
    }


    const nftFile = new Moralis.File("nftFile.jpg", fileInput.files[0]);
    await nftFile.saveIPFS();

    const nftFilePath = nftFile.ipfs();

    const metadata = {
        name: itemName.value,
        description: itemDescription.value,
        image: nftFilePath,
    };

    const nftFileMetadataFile = new Moralis.File("metadata.json", { base64: btoa(JSON.stringify(metadata)) });
    await nftFileMetadataFile.saveIPFS();

    const nftFileMetadataFilePath = nftFileMetadataFile.ipfs();

    const nftId = await mintNft(nftFileMetadataFilePath);

    user = await Moralis.User.current();
    const userAddress = user.get('ethAddress');

    

    if (typeForSale.checked) {
        try {
            await ensureMarketplaceIsApproved(nftId, TOKEN_CONTRACT_ADDRESS);
            await marketplaceContract.methods.addItemToMarket(nftId, TOKEN_CONTRACT_ADDRESS, itemPrice.value).send({ from: userAddress });
            alert("Item successfully add on sale!");
            window.location.href = "author.html";
        } catch (error) {
            alert("Error: " + error.code + " " + error.message);
        }
    } else {
        await ensureMarketplaceIsApproved(nftId, TOKEN_CONTRACT_ADDRESS);
        alert("Item successfully add in My Items!");
        window.location.href = "author.html";
    }

}

how to convert item price from wei to ether in this code. please help

https://docs.moralis.io/moralis-server/sdk-utils/moralis-units#converting-token-value-from-wei

//Convert token value to ETH style with 6 decimals
const tokenValue = Moralis.Units.FromWei("2000000000000000000", 6)

//Convert token value to ETH style with 18 decimals
//If you do not specify decimals, 18 decimals will be automatically used
const tokenValue = Moralis.Units.FromWei("2000000000000000000")
1 Like