diff --git a/content/languages/php.html b/content/languages/php.html index 06f4d95..99e5c37 100644 --- a/content/languages/php.html +++ b/content/languages/php.html @@ -14,13 +14,13 @@ ------------- The BC Math and Decimal extensions implement [arbitrary-precision](/formats/exact/) decimal math: - $a = '0.1'; - $b = '0.2'; - echo bcadd($a, $b); // prints 0.3 + $a = new \BcMath\Number('0.1'); + $b = new \BcMath\Number('0.2'); + echo $a + $b; // prints 0.3 - $a = new Decimal('0.1'); - $b = new Decimal('0.2'); - echo $a + $b; // prints 0.3 + $a = new \Decimal\Decimal('0.1'); + $b = new \Decimal\Decimal('0.2'); + echo $a + $b; // prints 0.3 How to Round ------------ @@ -29,17 +29,20 @@ $number = 4.123; echo number_format($number, 2); // prints 4.12 -If you are using the decimal extension, you can round using the `round` method: +If you are using either the Decimal or BC Math extensions, you can round using the `round` method: - $decimal = new Decimal("4.123"); - echo $decimal->round(2); // prints 4.12 + $number = new \BcMath\Number('4.123'); + echo $number->round(2); // prints 4.12 + + $decimal = new \Decimal\Decimal('4.123'); + echo $decimal->round(2); // prints 4.12 Resources --------- * [PHP manual](http://www.php.net/manual/en/index.php) * [Floating point types](http://www.php.net/manual/en/language.types.float.php) - * [BC Math extension](http://php.net/manual/en/ref.bc.php) - * [Decimal extension](http://php-decimal.io) + * [BC Math extension](https://php.net/manual/en/book.bc.php) + * [Decimal extension](https://php-decimal.github.io/) * [number_format()](http://php.net/manual/en/function.number-format.php)