views:

75

answers:

1

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?

+1  A: 

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 
Anthony Forloney
Sorry, I'm a little confused here - does this actually use the bc functions for rounding? If I have a number (say 16.99225), how would I use this technique to round to 4 digits?
nickf