网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站设计 > PHP
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 112.84.220.79
Old 2016-06-10, 06:59 AM
Chilly Chilly is offline
初级会员
 
Join Date: 2010-04-06
Posts: 2
Chilly 现在声名狼藉
Default 人民币数字转中文币制

[php]代码库

Code:





/** 


*  人民币数字转中文币制 


* @param  string $data  待转换的数字 


* @return  string 返回转换后的中文数字 


*/ 


function numberTocncap($data){ 


   $capnum = array( "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" ); 


   $capdigit = array( "", "拾", "佰", "仟" ); 


   $subdata = explode( ".", $data ); 


   $yuan = $subdata[0]; 


   $j = 0; 


   $nonzero = 0; 


   for( $i=0; $i<strlen($subdata[0]); $i++ ){ 


    if( $i==0 ){ //确定个位 


      if($subdata[1]){ 


        $cncap = (substr($subdata[0],-1,1)!=0) ? "元" : "元零"; 


      }else{ 


        $cncap = "元"; 


      } 


     } 


     if( $i==4 ){ //确定万位 


        $j = 0; 


        $nonzero = 0; 


        $cncap = "万" . $cncap; 


     } 


     if($i==8){ //确定亿位 


        $j = 0; 


        $nonzero = 0; 


        $cncap = "亿" . $cncap; 


     } 


     $numb = substr($yuan,-1,1); //截取尾数 


     $cncap = ($numb) ? $capnum[$numb].$capdigit[$j].$cncap : (($nonzero)?"零".$cncap:$cncap); 


     $nonzero = ($numb) ? 1 : $nonzero; 


     $yuan = substr($yuan,0,strlen($yuan)-1); //截去尾数 


     $j++; 


   } 


   if($subdata[1]){ 


    $chiao=(substr($subdata[1],0,1))?$capnum[substr($subdata[1],0,1)]."角":"零"; 


    $cent=(substr($subdata[1],1,1))?$capnum[substr($subdata[1],1,1)]."分":"零分"; 


   } 


   $cncap .= $chiao.$cent."整"; 


   $cncap = preg_replace("/(零)+/","\\1",$cncap); //合并连续“零” 


   return $cncap; 


}
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:10 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.