note 100498 added to function.number-format
| From: | GiltonGuma at osu1 dot php dot net | Date: | Wed, 20 Oct 2010 02:24:07 +0000 |
| Subject: | note 100498 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173292@lists.php.net to get a copy of this message | ||
/*
Formata numeros SEM e com arredondamento
Parametros:
[a] -> Numero
[b] -> Casa Decimais [0]
[c] -> Separador Milhares
[d] -> Separador Decimais
[e] -> Prefixo
[f] -> Arredondar [true; false] (Padrão: false)
*/
function Num_Format($a, $b = 0, $c = "", $d = "", $e = NULL, $f = false){
if (!$f){
$t = "0.";
for ($i = 1; $i <= ($b - 1); $i++) $t .= "0";
$t .= "1";
$a = round(((($a * 2) - $t) / 2), $b);
}
$ret = number_format($a, $b, $c, $d);
if ($e) $ret = $e.$ret;
return $ret;
}
$numero = 12345.6789;
echo "<b>Normal:</b> ".$numero;
echo "<hr />";
echo "<b>Sem arrendamento:</b> ".Num_Format($numero, 2, ",",
"");
echo "<br />";
echo "<b>Com arrendamento:</b> ".Num_Format($numero, 2, ",",
".", NULL, true);
echo "<hr />";
echo "<b>Sem arrendamento 4 casas e prefixo:</b> ".Num_Format($numero, 4,
",", ".", "R$");
echo "<br />";
echo "<b>Com arrendamento 4 casas e prefixo:</b> ".Num_Format($numero, 4,
",", ".", "R$");
----
Server IP: 69.147.83.197
Probable Submitter: 189.6.209.58
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/100498
Del: integrated -- https://master.php.net/note/delete/100498/integrated
Del: useless -- https://master.php.net/note/delete/100498/useless
Del: bad code -- https://master.php.net/note/delete/100498/bad+code
Del: spam -- https://master.php.net/note/delete/100498/spam
Del: non-english -- https://master.php.net/note/delete/100498/non-english
Del: in docs -- https://master.php.net/note/delete/100498/in+docs
Del: other reasons-- https://master.php.net/note/delete/100498
Reject -- https://master.php.net/note/reject/100498
Search -- https://master.php.net/manage/user-notes.php