[SOLVED]How to get the balance to display with correct decimals?

I have tried multiplying the balance by the decimals and its still too long.

code:

import styles from '../styles/UserBalances.module.css';


 


export default function UserBalances(props) {

    const RawData = props.data;

    const ConstructorData = [];


    const GetData = () => {
        if(RawData == null) {
            console.log('null')
        } else {
            for( let i = 0; i < RawData.length; i++) {
                ConstructorData.push(RawData[i])
            }
        }
        
    }
    GetData()
    



    return(
            <div className={styles.UserBalanceWrapper}>
                {
                    ConstructorData.length === 0 ? (
                        <p>Refresh For Data</p>
                    ): (
                        <div>
                            {ConstructorData.map((ConstructorData) => {
                                return(
                                    <div className={styles.DataBoxWrapper}>
                                        <p className={ styles.Name }>{ConstructorData.name}</p>
                                        <p className={ styles.Balance }>{ ConstructorData.balance }</p>
                                        <p className={ styles.Address }>{ConstructorData.token_address}</p>
                                    </div>
                                );
                            })}
                        </div>
                    )
                }
            </div>
    );
}

that is the code that gives the result you see in the photo now im wondering how i can format it correctly.

thank you!

Use Moralis.ETH.FromWei to change it from itโ€™s wei form to the decimal form~

1 Like

This worked thanks! just in case someone gets confused for react it was Moralis.Units.FromWei( )

2 Likes

ohhh yeah my bad typo :sweat_smile:

Youโ€™re good lol! I didnโ€™t specify react plus iโ€™m pretty sure that is correct for normal javascript.

yep definitely! :star_struck: