0
`ini_set('precision', 18);
$number2 = 5.00025051541321;
echo ($number2);

Output: 5.00025051541321019`

What can be the issue and if someone help me to solve that.

  • 1
    With 15 digits, `ini_set('precision', 15)` will provide that exact number. With precision 18, you will get further digits. Read up on [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken). – Markus AO Apr 14 '23 at 07:59
  • If you're wondering why, when you set the precision to 18, it doesn't display it as 5.00025051541321000, see the [linked duplicate](https://stackoverflow.com/questions/588004). If you're wondering something else, please clarify. – Steve Summit Apr 14 '23 at 12:33
  • 1
    Short answer: With less than infinite precision, floating point can't represent every number. And in binary, 5.00025051541321 is one of the numbers that can't be represented. The closest you can get is a binary number that, when converted back to decimal, looks like 5.000250515413210194992643664591014385223388671875 — or, when rounded to 18 significant digits, 5.00025051541321019. – Steve Summit Apr 14 '23 at 12:39

0 Answers0