Skip to content

Commit ed16470

Browse files
committed
Precision/Scale docs
1 parent 60f071b commit ed16470

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ $decimalAdded = $decimalOne->add($decimalTwo); // Now '3.3'
8080

8181
Note that due to immutability `$decimalOne` is not modified here. The re-assignment is necessary for the operation to persist.
8282

83+
### Precision/Scale
84+
Operations like `add()` use the higher of the scales of the operands.
85+
If both are the same, they would also stay the same.
86+
87+
With other operations like `multiply()`, they scale would be the addition of both operands' scale:
88+
```php
89+
$decimalOne = Decimal::create('1.55');
90+
$decimalTwo = Decimal::create('2.00');
91+
92+
echo $decimalOne->multiply($decimalTwo); // Prints '3.1000'
93+
94+
// Keeping 2 digit scale requires a 2nd argument
95+
echo $decimalOne->multiply($decimalTwo, 2); // Prints '3.10'
96+
```
8397

8498
## Contributing
8599

0 commit comments

Comments
 (0)