Forum Moderators: coopster

Message Too Old, No Replies

Long Decimal in PHP

Long Decimal, PHP

         

ayozzhero

6:41 am on Jul 26, 2004 (gmt 0)

10+ Year Member



I am using PHP 4.3.3

I am developing a site about astronomy the needs high precision calculation (that will use numbers of 20 decimal points). I've increased the precision value in php.ini to 25, but PHP seems to accept only 15 decimal points.

Is there any way I can make it?

coopster

2:01 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ayozzhero!

Which configuration directive did you set in the

php.ini
?

You may want to check out the BCMath Arbitrary Precision Mathematics Functions [php.net] that PHP has to offer as well.

ayozzhero

4:46 pm on Jul 26, 2004 (gmt 0)

10+ Year Member



Thank you for your fast reply, I really appreciate it.

in php.ini I put it as:
precision = 25

I've tried the BC functions and they work well. However, I need to maintain the same precision in other functions as well, e.g: pi(), cos(), sin()

<?php
ini_set('precision',25);

$abc1 = 0.04545454545454545454; //20 decimal points
$abc2 = 0.23232323232323232323; //20 decimal points
$abc1 = $abc1 + $abc2;

echo "<br>";
print "Result: " . $abc1;
echo "<p>";

$abc3 = 10/3;
print "abc3 " . $abc3;
print "<br>";

bcscale(25);
echo bcdiv(1100, 3) . "<br>";
echo bcmul(1234567890123456, 9876543210123456) . "<br>";

echo sin(1) . "<br>";
echo pi() . "<br>";

?>

/*
Using Windows Calculator (Scientific View)
sin(1) = 0.8414709848078965066525023216303//radian
pi = 3.1415926535897932384626433832795

PHP Result
abc3 3.3333333333333335
366.6666666666666666666666666
12193263112635260231976841383936
0.8414709848078965
3.1415926535897931

*/