PHP round for a number to the nearest 0.5

June 12th, 2012 | by admin |

For rating, the best solution to get the nearest 0.5 precision in PHP is

round($value*2) / 2

For example:

2.2 should give 2

2.3 should give 2.5

2.25 should give 2.5

Post a Comment