0

I have this number :

0.953163394286767

I assign this number to float variables.

$vari = (float)$appo;

But if i print i obtain :

0.95316339428677

How can resolve this problem?

bomberdini
  • 129
  • 1
  • 12

1 Answers1

4

You may use ini_set function here.

ini_set('precision', 16);
$appo =  0.953163394286767;
echo $vari = (float)$appo;//prints 0.953163394286767

Hope it helps! :)

Shashank Shah
  • 2,077
  • 4
  • 22
  • 46
  • 2
    Note that this cannot be set arbitrarily high. In fact, according to the PHP documentarion on floats, [16 digits seem to be the maximum sensible value](http://php.net/manual/de/language.types.float.php). Also have a look at this [demo](https://eval.in/534760). There is also http://stackoverflow.com/questions/14587290/can-i-rely-on-php-php-ini-precision-workaround-for-floating-point-issue?rq=1 which discusses the problem in depth. – syck Mar 11 '16 at 12:02