Hi,
How do you truncate or round a number to a set no. of decimal places in PHP?
eg
16.666666666667 => 16 or 16.7
I have looked for a truncate function and a rounding funtion but can't find one.
Any help would be great,
Thanks![]()
| SitePoint Sponsor |





Hi,
How do you truncate or round a number to a set no. of decimal places in PHP?
eg
16.666666666667 => 16 or 16.7
I have looked for a truncate function and a rounding funtion but can't find one.
Any help would be great,
Thanks![]()





round(); maybe?![]()
... or number_format()
Counter Code Enterprise Edition
Run your own web counter/statistics service
so it would be
This will actually give you 17PHP Code:echo round(16.66666667);
would give you 16.7PHP Code:echo round(16.666667, 1);
![]()
Wondering about best weight loss pill? Take a look at Proactol.





Thanks for the replies. I don't have time to look at them right now but they look like what I need.
Thanks
Bookmarks