PHP RMB amount to capitalization instance code, PHP case _php Tutorial

Source: Internet
Author: User
Tags learn php learn php programming

PHP renminbi amount to capitalization instance code, PHP capital case


PHP renminbi amount to capitalization, the essence is the number converted to Chinese capital, test a bit, very interesting, casually lose a number, you can print out its uppercase, beginner friends try It

PHP RMB amount to uppercase class ext_num2cny{static $basical = Array (0=> "0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU");   Static $advanced =array (1=> "Pick", "Bai", "Qian");   public static function Parsenumber ($number) {$number =trim ($number); if ($number >999999999999) return "The number is too large to handle. I'm sorry!   ";   if ($number ==0) return "0"; if (Strpos ($number, '. '))    {$number =round ($number, 2);    $data =explode (".", $number);    $data [0]=self::int ($data [0]);    $data [1]=self::d EC ($data [1]);   return $data [0]. $data [1]; }else{return Self::int ($number). '   The whole ';   }} public static function int ($number) {$arr =array_reverse (Str_split ($number));   $data = ";   $zero =false;   $zero _num=0;    foreach ($arr as $k = + $v) {$_chinese= ';    $zero = ($v ==0)? True:false;    $x = $k% 4;    if ($x && $zero && $zero _num>1) continue;      Switch ($x) {case 0:if ($zero) {$zero _num=0;       }else{$_chinese=self:: $basical [$v];      $zero _num=1;      } if ($k ==8) {$_chinese.= ' billion '; }elseif ($k ==4) {$_chinese.= ' million ';      } break;        Default:if ($zero) {if ($zero _num==1) {$_chinese=self:: $basical [$v];       $zero _num++;       }}else{$_chinese=self:: $basical [$v];      $_chinese.=self:: $advanced [$x];   }} $data =$_chinese. $data;  } return $data. ' Yuan ';   public static function Dec ($number) {if (strlen ($number) <2) $number. = ' 0 ';   $arr =array_reverse (Str_split ($number));   $data = ";   $zero _num=false;    foreach ($arr as $k = + $v) {$zero = ($v ==0)? True:false;    $_chinese= ";      if ($k ==0) {if (! $zero) {$_chinese=self:: $basical [$v];      $_chinese.= ' points ';     $zero _num=true;      }}else{if ($zero) {if ($zero _num) {$_chinese=self:: $basical [$v];      }}else{$_chinese=self:: $basical [$v];     $_chinese.= ' Corner ';   }} $data =$_chinese. $data;  } return $data; }}//use method $nun = new Ext_num2cny ();  echo EXT_NUM2CNY::P arsenumber (1234567.5);

results: One Bai and three hundred thousand Wu Wu Bai lu qi yuan

I hope this article is helpful for you to learn PHP programming,

http://www.bkjia.com/PHPjc/1058154.html www.bkjia.com true http://www.bkjia.com/PHPjc/1058154.html techarticle PHP renminbi amount to capitalize instance code, PHP Capital instance PHP renminbi capitalization, its essence is the number converted into Chinese capital, tested a bit, very interesting, casually lose ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.