# Precision arithmetics

How can i get precise number values out of PHP
like when i calculate this on a calculator or spread sheet, google… 7.33 * 14 = 102.62

but when i create a little function in PHP to do the same, i get this \$102.68
any one else come across this problem.

any help would be great.

``````
function calculate_intrest_charge(\$dailyrate)
{
\$result = (\$dailyrate * 14);
return \$result;

}

function money_form(\$cash)
{
return "\$" . number_format(\$cash, 2, '.', ' ,');

}

\$ic = calculate_intrest_charge(7.3343435512329);
echo money_form(\$ic);

/* why does PHP produce this value =
\$102.68 when it should be \$102.62  */

``````

i tryed to use it the GMP extensions with the demo code

``````
\$abs1 = gmp_abs("274982683358");
\$abs2 = gmp_abs("-274982683358");
echo gmp_strval(\$abs1) . "\
";
echo gmp_strval(\$abs2) . "\
";

``````

[B]

all i get is

Fatal error: Call to undefined function gmp_abs() in G:\xampplite\ est.php on line 120
[/B]

How do i get PHP to identify it…frustrating the hell out of me…all this should be built in man…

You might need to enable it in your php.ini file. Open it and search for gmp.dll

7.3343435512329 * 14 = 102.6808097

I don’t understand why you want PHP to return 102.62 ? Or am I missing something?

Didn 't even check the correctness of calculations ``````
echo money_form(bcmul("07.33","14")); /* i came up with this \$102.62 */

``````

but i want inputs to be more human readable, simple as using a daam calculator.

will installing GMP extensions solve all this…

forget it… i solved it myself…

Care to share how? ``````
function calculate_dailyrate(\$intrest)
{
\$result = bcdiv(\$intrest,365);
return round(\$result,2);
}

function money_form(\$cash)
{
return "\$" .  number_format(\$cash, 2, '.', ' ,');
}

echo money_form(calculate_dailyrate(2677.04))	/* Outputs: \$7.33 */;

``````

it does what i want for now anyway, for clean cut presentation outputs i used bcdiv() round() functions…