How to convert eg “40 million” to $40,000,000?

后端 未结 1 392
遇见更好的自我
遇见更好的自我 2021-01-06 18:38

I\'m looking for a way to covert a numeric string(as shown in the subject) to a proper one like $40,000,000.

Does php offer a function to do this?

Thanks fo

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 18:55

    $str = str_replace(' billion','000000000',$str);
    $str = str_replace(' million','000000',$str);
    $str = str_replace(' thousand','000',$str);
    $str = str_replace(' hundred','00'$str);
    
    setlocale(LC_MONETARY, 'en_US');    
    $str = money_format('%i',$str);    
    

    0 讨论(0)
提交回复
热议问题