How to Improve Mathematical Calculation in PHP
- 1). Open your PHP source file in a text editor, such as Windows Notepad.
- 2). Use the "bcadd(string, string, scale)" to add two arbitrary precision numbers together and return a value with a set number of decimal places equal to "scale". For example, "echo bcadd('1.235', '5', 4);" will print "6.2350".
- 3). Use the "bcsub(string, string, scale)" to subtract two arbitrary precision numbers. For example, "echo bcsub('1.235', '5', 4);" will print "-3.7650".
- 4). Use the "bcdiv(string, string, scale)" to divide two arbitrary precision numbers. For example, "echo bcdiv('105', '6.55957', 3);" will print "16.007".
- 5). Use the "bcpow(string, string, scale)" to raise the first arbitrary precision number to the second number. For example, "echo bcpow('4.2', '3', 2);" will print "74.08".
- 6). Save the PHP file.
Source...