Tutorial on how to convert PHP numbers to uppercase functions

Source: Internet
Author: User
This article we mainly share the PHP conversion to uppercase function method, when we write to pay the bill, we need to fill in the amount of the number of capital, said that it is not really written to write, in order to not appear embarrassing scenes, but also deliberately to practice the 10 words. Haha, of course, we can also convert in PHP, so we have the following conversion function:

/** * Amount lowercase to uppercase * @param $ns int input number */function CNY ($ns) {Static $cnums = Array ( "0", "one", "II", "three", "the", "WU", "Lu", "Qi", "ba", "JIU", $cnyunits = Array ("Circle", "angle", "fen"), $grees = Array ("Pick", "Bai", "Thousand", "    Million "," Pick "," Bai "," Qian "," billion ");    List ($ns 1, $ns 2) = Explode (".", $ns, 2);    $ns 2 = array_filter (Array ($ns 2[1], $ns 2[0]));    $ret = Array_merge ($ns 2, Array (Implode ("", _cny_map_unit (Str_split ($ns 1), $grees)), "");    $ret = Implode ("", Array_reverse (_cny_map_unit ($ret, $CNYUNITSS))); Return Str_replace (Array_keys ($cnums), $cnums, $ret);}    function _cny_map_unit ($list, $units) {$ul = count ($units);    $xs = Array ();        foreach (Array_reverse ($list) as $x) {$l = count ($xs); if ($x! = "0" | |! ( $l% 4) $n = ($x = = ' 0 '?) ": $x).        ($units [($l-1)% $ul]); else $n = Is_numeric ($xs [0][0])?        $x: ";    Array_unshift ($xs, $n); } return $xs;} 

View original >> Mamba children's shoes-blog-PHP numbers converted to uppercase functions


When we write to pay the bill, we need to fill in the number of capital, said that the real usually did not write it, in order to not appear embarrassing scenes, but also deliberately to practice the 10 words. Haha, of course, we can also convert in PHP, so we have the following conversion function:

/** * Amount lowercase to uppercase * @param $ns int input number */function CNY ($ns) {Static $cnums = Array ( "0", "one", "II", "three", "the", "WU", "Lu", "Qi", "ba", "JIU", $cnyunits = Array ("Circle", "angle", "fen"), $grees = Array ("Pick", "Bai", "Thousand", "    Million "," Pick "," Bai "," Qian "," billion ");    List ($ns 1, $ns 2) = Explode (".", $ns, 2);    $ns 2 = array_filter (Array ($ns 2[1], $ns 2[0]));    $ret = Array_merge ($ns 2, Array (Implode ("", _cny_map_unit (Str_split ($ns 1), $grees)), "");    $ret = Implode ("", Array_reverse (_cny_map_unit ($ret, $CNYUNITSS))); Return Str_replace (Array_keys ($cnums), $cnums, $ret);}    function _cny_map_unit ($list, $units) {$ul = count ($units);    $xs = Array ();        foreach (Array_reverse ($list) as $x) {$l = count ($xs); if ($x! = "0" | |! ( $l% 4) $n = ($x = = ' 0 '?) ": $x).        ($units [($l-1)% $ul]); else $n = Is_numeric ($xs [0][0])?        $x: ";    Array_unshift ($xs, $n); } return $xs;} 

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.