nickf
nickf

Reputation: 546025

Rounding using arbitrary precision libraries in PHP

I asked a question earlier about how to deal with rounding issues with floating point numbers in PHP, and was pointed to the bc and gmp libraries.

I've looked at the functions in these libraries but nothing jumped out at me when I was looking for one to round off the number.

How do you accurately round using these libraries?

Upvotes: 1

Views: 550

Answers (1)

Anthony Forloney
Anthony Forloney

Reputation: 91786

In How to ceil, floor and round bcmath numbers?, the answer gives you an implementation of bcround function, which utilizes its own bcfloor and bcceil function which seems to work.

As a test, here is what you asked for in your comment.

echo bcround(16.99225, 4); // outputs 16.9923 

Upvotes: 1

Related Questions