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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With