Alternative to money_format() Function in PHP on Windows Platform

前端 未结 13 1926
天命终不由人
天命终不由人 2020-12-01 09:02

I am using the money_format() function in PHP, which gives the following error:

Fatal error: Call to undefined function money_format()
         


        
13条回答
  •  伪装坚强ぢ
    2020-12-01 09:30

    **

    CLP money (moneda peso chileno, con formato miles)

    **

        function toMoney($val,$symbol='$',$r=0)
    {
        $n = $val; 
        $c = is_float($n) ? 1 : number_format($n,$r);
        $d = '.';
        $t = ',';
        $sign = ($n < 0) ? '-' : '';
        $i = $n=number_format(abs($n),$r); 
        $j = (($j = strlen($i)) > 2) ? $j % 2 : 0; 
    
       return  $symbol.$sign .($j ? substr($i,0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
    
    }
    
    echo toMoney(45); $45
    echo toMoney(4500);  $4,500
    echo toMoney(45000);  $45,000
    

提交回复
热议问题