I have a situation where I am calculating the number of ad impressions per month. I found several examples rounding up but they don't work in my case. The sample data I'm working with shows 166,666 impressions per month (166,666 x 12) is being rounded to 2 million. When multiplying 166666 by 12 then using the ceil() or round() functions, I get 1999992. I found an example of rounding to the nearest million but it was done in C or C++.
Asked
Active
Viewed 124 times
1 Answers
0
I've tested this:
<?php
//
$val = 166666 * 12;
//
echo ceil($val/1E6)*1E6 . "<br />"; // => 2000000
echo number_format(ceil($val/1E6)*1E6, 0) . "<br />"; // => 2,000,000
?>

jacouh
- 8,473
- 5
- 32
- 43