Alternative to money_format() Function in PHP on Windows Platform

前端 未结 13 1977
天命终不由人
天命终不由人 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条回答
  •  猫巷女王i
    2020-12-01 09:36

    I don't understand why @Ajeet is making it so complicated why not do like this, It also now works for 4 digit numbers to answer @bharanikumar "but it is not working for the '0899'"

    function toMoney($val,$symbol='$',$r=2)
    {
        $n = $val;
        $sign = ($n < 0) ? '-' : '';
        $i = number_format(abs($n),$r);
    
        return  $symbol.$sign.$i;
    }
    

提交回复
热议问题