Code to convert lowercase amounts to uppercase amounts using PHP (accurate to minutes)_PHP Tutorial

WBOY
Release: 2016-07-21 15:22:00
Original
984 people have browsed it

Copy code The code is as follows:

/**
*Function to convert numeric amounts into Chinese uppercase amounts
*String Int $num Lowercase numbers or lowercase strings to be converted
*return uppercase letters
*Two decimal places
**/
function get_amount($num){
$c1 = "Zero, one, two, three, four, five, six, eight, nine";
$c2 = "One cent, one hundred thousand, one hundred, billion";
$num = round($num, 2);
$num = $num * 100;
if (strlen($num) > 10) {
return "The data is too long, I don’t have such a big money, check it";
}
$i = 0;
$c = "";
while (1) {
if ($i == 0) {
$n = substr($num, strlen( $num)-1, 1);
} else {
$n = $num % 10;
}
$p1 = substr($c1, 3 * $n, 3);
$p2 = substr($c2, 3 * $i, 3);
if ($n != '0' || ($n == '0' && ($p2 == '100 million' | | $p2 == 'ten thousand' || $p2 == 'yuan'))) {
$c = $p1 . $p2 . $c;
} else {
$c = $p1 . $c;
}
$i = $i + 1;
$num = $num / 10;
$num = (int)$num;
if ($num = = 0) {
break;
}
}
$j = 0;
$slen = strlen($c);
while ($j < $slen) {
$m = substr($c, $j, 6);
if ($m == 'zero yuan' || $m == 'zero million' || $m == 'zero million' || $m == 'zero zero') {
$left = substr($c, 0, $j);
$right = substr($c, $j + 3);
$ c = $left . $right;
$j = $j-3;
$slen = $slen-3;
}
$j = $j + 3;
}

if (substr($c, strlen($c)-3, 3) == 'zero') {
$c = substr($c, 0, strlen($c)-3) ;
}
if (empty($c)) {
return "zero yuan";
}else{
return $c . "whole";
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324762.htmlTechArticleCopy the code code as follows: /** *Function to convert digital amount into Chinese uppercase amount*String Int $num to be Converted lowercase numbers or lowercase strings *return uppercase letters *two decimal places...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!