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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.