note 73069 deleted from function.number-format by cmb

From: Date: Sun, 08 Sep 2019 10:18:28 +0000
Subject: note 73069 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212127@lists.php.net to get a copy of this message
Note Submitter: ted at qtis dot co dot nz ---- I use the following to get around the negative zero problem: <?php function currency_format($amount, $precision = 2, $use_commas = true, $show_currency_symbol = false, $parentheses_for_negative_amounts = false) { /* ** An improvement to number_format. Mainly to get rid of the annoying behaviour of negative zero amounts. */ $amount = (float) $amount; // Get rid of negative zero $zero = round(0, $precision); if (round($amount, $precision) == $zero) { $amount = $zero; } if ($use_commas) { if ($parentheses_for_negative_amounts && ($amount < 0)) { $amount = '('.number_format(abs($amount), $precision).')'; } else { $amount = number_format($amount, $precision); } } else { if ($parentheses_for_negative_amounts && ($amount < 0)) { $amount = '('.round(abs($amount), $precision).')'; } else { $amount = round($amount, $precision); } } if ($show_currency_symbol) { $amount = '$'.$amount; // Change this to use the organization's country's symbol in the future } return $amount; } ?>

« previous php.notes (#212127) next »