Advertisement
diabliyo

mbnumber_format sustituto para funcion oficial number_format

Mar 19th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. #
  2. # $n= numero
  3. # $c= cantidad digitos a la derecha del punto (centavos o decimales)
  4. # $del= delimitador para los centavos
  5. # $miles= delimitador para los miles o mas...
  6. #
  7. function mbnumber_format( $n, $c, $del='.', $miles=',', $admin=false)
  8.     {
  9.     $d= explode(".", $n);
  10.     $c= ($admin ? $c:($_SESSION["round_decimals"] ? $_SESSION["round_decimals"]:$c)); # numero de decimales, default: 2
  11.  
  12.     $centavos='';
  13.     for( $i=0; $i<$c; $i++ )
  14.         {
  15.         if( $i<$c )
  16.             $centavos .= (isset($d[1][$i]) ? $d[1][$i]:0);
  17.         }
  18.  
  19.     $num= $d[0].$del.($admin ? $centavos:($_SESSION["round_cero"] ? '':$centavos));
  20.     return number_format($num, $c, $del, $miles);
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement