There is an easier way.
number_format is for outputting numbers or rounding prime numbers. number_format gives us the ability to make well-rounded rounded numbers for better user convenience. To calculate and store numbers in a MYSQL database, use this.
Save your numbers in MYSQL always as a DECIMAL type, not a FLOAT. There are many mistakes if you want to calculate the FLOAT fields.
Instead of using English notation.
$number = 1234.56; // english notation without thousands separator $english_format_number = number_format($number, 2, '.', ''); // // 1234.57
And now you can calculate and save it without errors. Always remember that storing numbers in $ var is always a string. Yes, you can use the deifine type, but in the first case it does not matter, and it can be explained here.
For more information on number_format see here โ http://php.net/manual/en/function.number-format.php
source share