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

NumberValue and NumbersArray take 2 #50

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,53 @@ $stringsArray = Wrap::iterable($range(0, 10))
});
```

### `NumberValue`

Object wrapping number (float or int).

```php
<?php

use GW\Value\Wrap;

$number = Wrap::number(100)
->add(20)
->subtract(1)
->multiply(2)
->divide(3)
->modulo(100)
->calculate('sqrt')
->round(2);
// ...

$formattedNumber = $number->format(2, '.', ',');

```

### `NumbersArray`

Object wrapping array of numbers wrapped in NumberValue.

```php
<?php

use GW\Value\NumberValue;
use GW\Value\Wrap;

$numbers = Wrap::numbersArray([1, 2, 3, 4]);

$sum = $numbers->sum()->format(2)->toString();
$min = $numbers->min()->format(2)->toString();
$max = $numbers->max()->format(2)->toString();
$avg = $numbers->average()->format(2)->toString();

$customSum = $numbers->reduceNumber(
fn(NumberValue $sum, NumberValue $next): NumberValue => $sum->add($next->round()),
0
);

```

## Documentation

For full methods reference and more examples see [here](./docs/examples.md).
Expand Down
Loading