码迷,mamicode.com
首页 > 其他好文 > 详细

数字金额转汉字金额

时间:2014-05-18 19:27:44      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

早上公交上总想这个问题,终于写出来了,不知道有错误没

bubuko.com,布布扣
 1 $chinese = array("零","一","二","三","四","五","六","七","八","九");
 2         $str = 140032002005;
 3         $arr = array();
 4         
 5         $num = floor(strlen($str)/4);
 6         $ss = substr($str, 0, strlen($str)-$num*4);
 7         $i = 0;
 8         while($num>0){
 9             $arr[] = substr($str, -4-$i*4,4);
10             $num--;
11             $i++;
12         }
13         if($ss != "") $arr[] = $ss;
14         $strr = array();
15         foreach ($arr as $k => $v) {
16             $strrr = "";
17             for ($j=strlen($v);$j>0;$j--) {
18                 switch ($j) {
19                     case 4:
20                         $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."千" : $chinese[0];
21                         break;
22                     case 3:
23                         $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."百" : ($v[strlen($v)-$j+1]==0 ? "" : $chinese[0]);
24                         break;
25                     case 2:
26                         $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]]."十" : ($v[strlen($v)-$j+1]==0 ? "" : $chinese[0]);
27                         break;
28                     case 1:
29                         $strrr .= $v[strlen($v)-$j] != 0 ? $chinese[$v[strlen($v)-$j]] : "";
30                         break;
31                 }
32             }
33             if($k%2 == 1) $strrr = $strrr."万";
34             if($k%2 == 0 && $k!=0) $strrr = $strrr."亿";
35             $strr[] = $strrr;
36         }    
37         header("Content-type: text/html; charset=utf-8");//浏览器改不了编码了
38         krsort($strr);
39         var_dump(implode("", $strr));exit;    
bubuko.com,布布扣

 

数字金额转汉字金额,布布扣,bubuko.com

数字金额转汉字金额

标签:style   blog   class   code   c   java   

原文地址:http://www.cnblogs.com/moleng/p/3732702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!