note 120479 deleted from function.money-format by cmb

From: Date: Wed, 30 Jun 2021 15:17:33 +0000
Subject: note 120479 deleted from function.money-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216561@lists.php.net to get a copy of this message
Note Submitter: jonah at jonah dot name ---- Be careful when using money_format with rounding. It uses floating-point numbers to round, so the precision is not perfect. Specifically, rounding over 63.5 may be incorrectly rounded down. See the bug report here: https://bugs.php.net/bug.php?id=61787 Bearing this in mind, I'd recommend using http://php.net/round on your number first. $number = 64.005; echo money_format('%.2n', $number); // $65.00 (incorrect behavior for PHP_ROUND_HALF_UP) $number2 = round($number, 2); echo money_format('%.2n', $number2); // $65.01 (correct)

« previous php.notes (#216561) next »