There’s a couple of ways to remove decimal places from a number in PHP…
$out = number_format($val,0); $out = (int) @floor($val);
Interestingly, we ran a real-world test case of 10 million iterations of doing each of these, and it turns out that method #2 is approximately 0.5 seconds quicker. So there you have it, if you want to be 0.5 seconds quicker when removing decimal places from a number 10 million times.. then use the second method.
No tags

Author comment by james · November 26, 2008 at 11:51 am
Indeed a couple of people pointed out on my blog of the same post, it would be much quicker to do: