(EXT) PHP Digital amount to Chinese capital amount

Source: Internet
Author: User

Tag:strlen    string    php   turn   function    --    Chinese    ring    remove    

function Floatohz ($value) {
$result = ";
$v _a=array (' min ', ' Corner ', ' 0 ', ' block ', ' ten ', ', ' hundred ', ' thousand ', ' million ', ' ten ', ' hundred ', ' thousand ', ' billion ');
$v _b=array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' VI ', ' VII ', ' VIII ', ' IX ', ' ten ');
$v _c=array ();
$value = (string) $value;
Keep two digits after the decimal point
$value =sprintf ("%0.2f", $value);
Get string length
$len =strlen ($value);
Remove string from back to front
for ($i = $len; $i >=0; $i--) {
$val = $value [$i];
if ($val! = '. ') {
When encountered is 0 o'clock without units
if ($val = = ' 0 ') {
$v _c[]= $v _b[$val];
} else{
e.g. Four points
$v _c[]= $v _b[$val]. $v _a[$len-$i-1];
}

}
}
Array inversion
$v _c=array_reverse ($v _c);
Output from the past
foreach ($v _c as $val) {
$result. = $val;
}
unset ($v _a); unset ($v _b); unset ($v _c);
return $result;
}

$value = ' 45123056.78 ';
$value = ' 23058.04 ';
Print floatohz ($value);
Exit

(EXT) PHP Digital amount to Chinese capital amount

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.