my problem is the decimal value of USDC is 6. The amount of 0.1 we enter turns into 100000.

I want to return it with php so that's what I want. When I enter the number and decimal value in a method, it should give me the output of amount.

function prepareAmount(amount, decimals) {
   // code

// Examples
$amount = 100000;
$decimals = 6;

prepareAmount($amount, $decimals); // 0.1;

$amount = 1000000;
$decimals = 6;

prepareAmount($amount, $decimals); // 1;

This is how I solved it guys.

function prepareAmount($amount, $decimals)
        $length = '1' . str_repeat('0', $decimals);
        return floatval(bcdiv($amount, $length, $decimals));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.