Subtract 1 from a large number in PHP

php

Solution

If you have the BCMath extension you can use this:

$a = bcsub('294867828828426241', '1');

echo $a; // 294867828828426240

However, testing on my 64-bit server your code should work correctly. I'm not sure, but you can check to see if increasing the precision directive in your `php.ini` will make any difference. I have mine set at 14.

Problem

I need to subtract 1 from the number `294867828828426241` in PHP. However when I do ``` $a = 294867828828426241 - 1; ``` I receive the floating point number `2.94867828828E+17`. Which, when resolved by `number_format()` gives the original number. How can i get the correct value, please? This needs to be able to be able work with different numbers.

Original source