brick / math

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

Rounding is necessary to represent the result of the operation at this scale. #65

Closed samyan closed 2 years ago

samyan commented 2 years ago

Hi. Why i get the error of the title.

Test case:

$p = BigDecimal::of(1.54);

print_r(BigDecimal::of(100)->dividedBy($p, RoundingMode::HALF_UP));
samyan commented 2 years ago

Solved setting the precision in this way

$p = BigDecimal::of(1.54);
$precision = 2;

print_r(BigDecimal::of(100)->dividedBy($p, $precision, RoundingMode::HALF_UP));

If there is no other ways to do, the we can close the issue.

BenMorel commented 2 years ago

Hi, indeed, the rounding mode is the 3rd parameter, the 2nd being the precision! :+1: