0

The result of below operation should be 0.63686637617647057, but I get this result instead : 0.63686637617647.

Result that I expect:

1 - 0.36313362382352943 = 0.63686637617647057;

Result of php:

1 - 0.36313362382352943 = 0.63686637617647

How can I do to make php not round the result?

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
Samira
  • 11
  • 1
  • 5
    Please read up about how computers handle floating point numbers – Ed Heal Dec 02 '17 at 12:29
  • 8
    Possible duplicate of [Why Are Floating Point Numbers Inaccurate?](https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate) – tambre Dec 02 '17 at 12:30
  • 5
    Check this out: [What Every Programmer Should Know About Floating-Point Arithmetic](http://floating-point-gui.de) – eis Dec 02 '17 at 12:32
  • 3
    There are limits to the precision of variables. If you want to have arbitrary length precision, check this out: http://php.net/manual/en/book.bc.php Also read the links given above, but they do not directly help you with your problem. – Bart Friederichs Dec 02 '17 at 12:37
  • @BartFriederichs I've used bcadd and bcsub functions. Thanks – Samira Dec 11 '17 at 05:29
  • @tambre Thanks for your help – Samira Dec 11 '17 at 05:30

0 Answers0