php封装好的人民币数值转中文大写类

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php封装好的人民币数值转中文大写类脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP封装好的人民币数值转中文大写类

 2) {
      if($is_round){
        if(round(floatval("0.".$dec),2) == 1 && $dec_to_int){//小数进位到个位
          $int = empty($int)?1: strval($parts[0]+1);
          $dec = 0;
        }elseif(round(floatval("0.".$dec),2) == 1){//小数不进位到个位
          $dec = "99";
        }else{
          $dec = substr(strrchr(strval(round(floatval("0.".$dec),2)),'.'),1);
          echo $dec;die('boss');
        }
      }else{
        $dec = substr($parts[1],2);
      }
    }
    // 当number为0.001时,小数点后的金额为0元
    if (empty($int) && empty($dec)) {
      return '零';
    }
// 定义
$chs = array('0','壹','贰','叁','肆','伍','陆','柒','捌','玖');
$uni = array('','拾','佰','仟');
$dec_uni = array('角','分');
$exp = array('','万');
$res = '';

// 整数部分从右向左找
for ($i = strlen($int) - 1,$k = 0; $i >= 0; $k++) {
  $str = '';
  // 按照<a href="https://www.js-code.COM/tag/zhongwen/" target="_blank" class="keywords">中文</a>读写习惯,每4个字为一段进行转化,i一直在减
  for ($j = 0; $j < 4 && $i >= 0; $j++,$i--) {
    $u = $int{$i} > 0 ? $uni[$j] : ''; // 非0的数字后面<a href="https://www.js-code.com/tag/tianjia/" target="_blank" class="keywords">添加</a>单位
    $str = $chs[$int{$i}] . $u . $str;
  }
  //echo $str."|".($k - 2)."<br>";
  $str = rtrim($str,'0');// 去掉末尾的0
  $str = PReg_replace("/0+/","零",$str); // 替换多个连续的0
  if (!isset($exp[$k])) {
    $exp[$k] = $exp[$k - 2] . '亿'; // 构建单位
  }
  $u2 = $str != '' ? $exp[$k] : '';
  $res = $str . $u2 . $res;
}

// 如果小数部分处理完之后是00,需要处理下
$dec = rtrim($dec,'0');

// 小数部分从左向右找
if (!empty($dec)) {
  $res .= $int_unIT;
  // 是否要在整数部分以0结尾的数字后附加0,有的系统有这要求
  if ($is_extra_zero) {
    if (substr($int,-1) === '0') {
      $res.= '零';
    }
  }
  for ($i = 0,$cnt = strlen($dec); $i < $cnt; $i++) {
    $u = $dec{$i} > 0 ? $dec_uni[$i] : ''; // 非0的数字后面<a href="https://www.js-code.com/tag/tianjia/" target="_blank" class="keywords">添加</a>单位
    $res .= $chs[$dec{$i}] . $u;
  }
  $res = rtrim($res,'0');// 去掉末尾的0
  $res = preg_replace("/0+/",$res); // 替换多个连续的0
} else {
  $res .= $int_unit . '整';
}
return $number < 0 ? "(负)".$res : $res;

}

}

脚本宝典总结

以上是脚本宝典为你收集整理的php封装好的人民币数值转中文大写类全部内容,希望文章能够帮你解决php封装好的人民币数值转中文大写类所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: