note 73069 added to function.number-format

From: Date: Wed, 07 Feb 2007 23:38:06 +0000
Subject: note 73069 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-123099@lists.php.net to get a copy of this message
I use the following to get around the negative zero problem: 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; } ---- Server IP: 202.89.36.242 Probable Submitter: 131.203.76.110 ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- https://master.php.net/note/edit/73069 Del: integrated -- https://master.php.net/note/delete/73069/integrated Del: useless -- https://master.php.net/note/delete/73069/useless Del: bad code -- https://master.php.net/note/delete/73069/bad+code Del: spam -- https://master.php.net/note/delete/73069/spam Del: non-english -- https://master.php.net/note/delete/73069/non-english Del: in docs -- https://master.php.net/note/delete/73069/in+docs Del: other reasons-- https://master.php.net/note/delete/73069 Reject -- https://master.php.net/note/reject/73069 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123099) next »