|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-01-07 10:55 UTC] objecttothis at gmail dot com
[2020-01-07 11:39 UTC] cmb@php.net
[2020-01-07 12:00 UTC] objecttothis at gmail dot com
[2020-01-08 13:16 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
Description: ------------ There is no mode in round() that always rounds up or always rounds down. To do this you have to use ceil() or floor() which do not use precision, so the result will always be an integer. If PHP_ROUND_UP and PHP_ROUND_DOWN modes were added, it would resolve this problem. Test script: --------------- <?php function round_up($number, $precision = 2) { $fig = (int) str_pad('1', $precision, '0'); return (ceil($number * $fig) / $fig); } function round_down($number, $precision = 2) { $fig = (int) str_pad('1', $precision, '0'); return (floor($number * $fig) / $fig); } ?>