A
A
Anastasia2020-04-26 02:50:14
PHP
Anastasia, 2020-04-26 02:50:14

Why do I get a large remainder when adding numbers?

Hello. There is such an array:
5ea4ca8e69e4b483669400.png
we are talking about php.

When adding this array, I get 203959.97999999998
I added it through array_sum and with this crutch:

foreach ($qqq as $value) {
  $qsum = $qsum + $value;
}
echo "$qsum";

(I just didn't know about array_sum)

In both cases the result is the same. Where does this residue come from?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-04-26
@nastya97core

floating point numbers are not guaranteed to be accurate.
https://www.php.net/manual/ru/language.types.float.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question