Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating PHP page to match PHP 8.4 news #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions content/languages/php.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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)