Make PHP's bc round instead of truncate?

591 Views Asked by At

I'd like bcadd(4.9,3) to return 8 rather than 7. I'm using an example without lots of decimal places here, but the basic idea (that I want to round, rather than truncate) still stands. How do I do this?

1

There are 1 best solutions below

0
On

bcadd lets you specify precision (and bcscale). You can change it to bcadd(4.9,3,$some_huge_number) if you have a decimal max .. then you can just use round().