Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what is function can sum two big numbers php

I’m trying to Sum of two large numbers for some reason

<?php
$a = 50000000000.000000000000000000;
$b = 100000000000000000000000000000;
$sum = $a+$b;
echo $sum;

But the output appears like this:

1.0E+290

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a function that can be used to sum two large numbers?

>Solution :

You can use bcmath extension that provide functions to perform mathematical operations with numbers of any size and precision up to 2147483647 decimal digits, if there is sufficient memory.

Example :

<?php
$a = '50000000000.000000000000000000';
$b = '100000000000000000000000000000';
echo bcadd($a,$b);
// result : 100000000000000000050000000000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading