brick / math

Arbitrary-precision arithmetic library for PHP
MIT License
1.78k stars 75 forks source link

How to accept any scale without rounding #63

Closed bendavies closed 2 years ago

bendavies commented 2 years ago

Hi,

Is there anyway to accept any resulting scale without doing an rounding? Best with an example:

BigDecimal::of('1')->dividedBy('1000');

will result in RoundingNecessaryException, but really i want to allow the scale to be set to whatever is necessary. i.e i want to result to be:

BigDecimal::ofUnscaledValue(1, 3)

My work around at the moment is:

BigRational::of('1/1000')->toBigDecimal();

which gets me the result i want.

Thanks!

bendavies commented 2 years ago

i found BigDecimal::exactlyDividedBy()!