Search code examples
phpgnugmp

PHP gmp_mul() Error: Unable to convert variable to GMP - wrong type


I'm using PHP gmp functions.

I want to do the following mathematical statements:

$profit_percent = 2405.665;
$bill_line['purchase_average_value'] = 36000000000;   

$r = (1 + ($profit_percent / 100));
$r2 = $bill_line['purchase_average_value'];
$unit_price_with_profit = gmp_mul($r, $r2);

But the following error occurs:

gmp_mul(): Unable to convert variable to GMP - wrong type


Solution

  • If you see the description for the GMP library:

    These functions allow for arbitrary-length integers to be worked with using the GNU MP library.

    You are trying to pass a floating number to gmp_mul(). That will fail always.