SilverStripe\Omnipay\Helper\PaymentMath
Helper class to deal with payment arithmetic.
Note of advice: If PHP wasn't compiled with BC Math (http://php.net/manual/en/book.bc.php), you can run into
number-overflow issues quickly when dealing with high precision and/or multiplication of large numbers.
Synopsis
class PaymentMath
{
- // members
- private static integer $precision = 2;
- private static bool $useBcMath = true;
- // methods
- public static string subtract()
- public static string add()
- public static string multiply()
- public static int compare()
- private static string formatFloat()
Hierarchy
Uses
- SilverStripe\Core\Config\Configurable
Members
private
- $precision
—
int
Desired precision for the output strings. - $useBcMath
—
SilverStripe\Omnipay\Helper\bool
Whether or not to use bc-math functions. Should be set to true, if possible.
Methods
private
- formatFloat() — Format a float to string
public
- add() — Add two numbers that are represented as a string Numbers will not be rounded but floored instead! So 0.22 + 0.27 with a precision of 1 will result in 0.4!
- compare() — Compare two numbers that are represented as a string
- multiply() — Multiply two numbers that are represented as a string Numbers will not be rounded but floored instead! So 0.001 * 10 with a precision of 1 will result in 0!
- subtract() — Subtract two numbers that are represented as a string.