krowinski/bcmath-extended

Looks like roundUp doesn't work as expected

MrNomNom opened this issue · 6 comments

Please provide the following details.

  • Operating System:
  • PHP Version: <7.2>

Steps required to reproduce the problem.

BC::roundUp("1.11111111", 2) = "1.12"

This issue has been resolved since the latest stable version is released.

This issue has been resolved since the latest stable version is released.

I tried on version 5.0.0 with PHP 7.3 and still got this error.

\BCMathExtended\BC::roundUp("1.160711",2)

# Output: 1.17

@MrNomNom and @mydansun, thank you for your report.

That's right. And I also get the same issue.

Reopen this issue and I take look at this rounding problem.

I think if we want to get the rounding result, using the round instead.

\BCMathExtended\BC::round("1.160711",2);

// Output: 1.16

The roundUp will round-up without condition.

I do not know if I got the right understanding with this method. However, I think it should have the following results.

\BCMathExtended\BC::roundUp("1.160",2)
# Expected 1.16

\BCMathExtended\BC::roundUp("1.1601",2)
# Expected 1.16

@mydansun, if you want to get these expected results you provide, using the \BCMathExtended\BC::round method instead.

The \BCMathExtended\BC::roundUp method behavior is not same as \BCMathExtended\BC::round method.

The \BCMathExtended\BC::roundUp behavior is same as \BCMathExtended\BC::ceil method and its parameter can allow the result with precision, but the \BCMathExtended\BC::ceil method cannot.