如何利用PHP金额数字转换成英文呢?就跟随百分网小编一起去了解下吧,想了解更多相关信息请持续关注我们应届毕业生考试网!

  代码如下:

  <?php

  $num=1220.01;

  echo fmoney($num);//结果:1,220.21

  echo umoney($num);

  //结果:ONE THOUSAND AND TWO HUNDRED TWENTY DOLLARS AND TWENTY-ONE CENTS ONLY

  echo umoney($num,"rmb");

  //结果:ONE THOUSAND AND TWO HUNDRED TWENTY YUAN AND TWENTY-ONE FEN ONLY

  //define

  //格式化货币

  function fmoney($num) {

  $num=0+$num;

  $num = sprintf("%.02f",$num);

  if(strlen($num) <= 6) return $num;

  //从最后开始算起,每3个数它加一个","

  for($i=strlen($num)-1,$k=1, $j=100; $i >= 0; $i--,$k++) {

  $one_num = substr($num,$i,1);

  if($one_num ==".") {

  $numArray[$j--] = $one_num;

  $k=0;

  continue;

  }

  if($k%3==0 and $i!=0) {

  //如果正好只剩下3个数字,则不加','

  $numArray[$j--] = $one_num;

  $numArray[$j--] = ",";

  $k=0;

  } else {

  $numArray[$j--]=$one_num;

  }

  }

  ksort($numArray);

  return join("",$numArray);

  }

  function umoney($num,$type="usd") {

  global $numTable,$commaTable,$moneyType;

  //global $numTable;

  $numTable[0]="ZERO ";

  $numTable[1]="ONE ";

  $numTable[2]="TWO ";

  $numTable[3]="THREE ";

  $numTable[4]="FOUR ";

  $numTable[5]="FIVE ";

  $numTable[6]="SIX ";

  $numTable[7]="SEVEN ";

  $numTable[8]="EIGHT ";

  $numTable[9]="NINE ";

  $numTable[10]="TEN ";

  $numTable[11]="ELEVEN ";

  $numTable[12]="TWELVE ";

  $numTable[13]="THIRTEEN ";

  $numTable[14]="FOURTEEN ";

  $numTable[15]="FIFTEEN ";

  $numTable[16]="SIXTEEN ";

  $numTable[17]="SEVENTEEN ";

  $numTable[18]="EIGHTEEN ";

  $numTable[19]="NINETEEN ";

  $numTable[20]="TWENTY ";

  $numTable[30]="THIRTY ";

1.《金额英文 PHP金额数字转换成英文》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《金额英文 PHP金额数字转换成英文》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/jiaoyu/97341.html