Home  >  Article  >  Backend Development  >  将数值(千亿以下)转换为大写人民币解决办法

将数值(千亿以下)转换为大写人民币解决办法

WBOY
WBOYOriginal
2016-06-13 13:53:51867browse

将数值(千亿以下)转换为大写人民币
rt:将数值(千亿以下)转换为大写人民币.用PHP实现。PHPer 快啊

------解决方案--------------------
http://www.phparticle.net/htmldata/2268/1/
------解决方案--------------------

PHP code
 
error_reporting(2047);#报告所有非法的错误 
ob_start(); 

function  RMB ($RMB=0,$Format='') 
{ 
/* 
Function          : 小写金额转换大写金额 支持元角分厘毫 的PHP函数 
Author            : 纯粹误会 zh5j.com QQ:44922032 
Time              : 2005-5-18 
Parameters        : $RMB是小写金额,$Format是返回格式化后的的小写金额 
Usage             : $RMB=RMB("1255888","money");echo $RMB; echo $money; 
Thanks            : 奶瓶、石头、ej99 
*/ 
    $RMB=@preg_Replace( 
        array('/([, ]|¥|0$|)/','/(.){2,}/'), 
        array('','.'), 
        $RMB); 
    if(eregi("[^0-9.]",$RMB))return "非法金额"; 
    if($RMB==0)return "零元整"; 
    elseif($RMB>pow(10,12))return "金额必须小于千亿"; 

    $re   = ''; 
    $arr1 = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖'); 
    $arr2 = array('元','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟'); 
    $arr3 = array('角','分','厘','毫'); 
    $pre1 = count($arr2);  #单位精确度 precision 
    $pre2 = count($arr3);  #小数位精确度 precision 
    $arr  = @explode(".",$RMB);#按小数点切割金额 
    $len1 = @strlen($arr[0]);  #整数位长度 
    $len2 = @strlen($arr[1]);  #小数位长度 
    for($i=0; $i <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn