In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you php how to achieve the amount of money and Chinese conversion, I hope you will learn something after reading this article, let's discuss it together!
Php to achieve the amount and Chinese conversion methods: 1, to create a PHP sample file; 2, through the "public function convertAmountToCn ($amount, $type = 1) {.}" to convert the numerical amount to Chinese capital amount.
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
The PHP amount is changed to uppercase Chinese.
The code is as follows:
/ * convert numeric amount to Chinese uppercase amount * @ param $amount float amount (supported to points) * @ param $type int repair type, 0: to corner correction 1: to meta-complement * @ return mixed Chinese capital amount * / public function convertAmountToCn ($amount, $type = 1) {/ / determine whether the output amount is a number or numeric string if (! is_numeric ($amount)) {return "the amount to be converted can only be numeric!" } / / if the amount is 0, the direct output of "zero integer" if ($amount = = 0) {return "zero integer";} / / the amount cannot be negative if ($amount)
< 0) { return "要转换的金额不能为负数!"; } // 金额不能超过万亿,即12位 if(strlen($amount) >12) {return "the amount to be converted cannot be trillions or more!";} / / the predefined array of Chinese conversions $digital = array ('zero', 'one','II','3', 'restaurant','Wu','Lu','Qi', 'Qing', 'Jiu') / / the predefined unit converted array $position = array ('thousand', 'hundred', 'pick', 'hundred', 'thousand', 'hundred', 'ten thousand', 'ten thousand', 'hundred', 'pick', 'yuan'); / / split the numerical string of the amount into an array of $amountArr = explode ('.', $amount). / / split the integer numeric string into an array of $integerArr = str_split ($amountArr [0], 1); / / replace the integer portion with an uppercase Chinese character $result =''; / / prefix $integerArrLength = count ($integerArr); / / the length of the integer array $positionLength = count ($position) / / the length of the unit array for ($I = 0; $I < $integerArrLength; $iTunes +) {/ / if the value is not 0, convert if ($integerArr [$I]! = 0) {$result = $result. $digital [$integerArr [$I]]. $position [$positionLength-$integerArrLength + $I];} else {/ / if the value is 0 and the unit is 100 million, ten thousand yuan, the unit if (($positionLength-$integerArrLength + $I + 1)% 4 = 0) {$result = $result is directly displayed. $position [$positionLength-$integerArrLength + $I];} / if decimal places are also converted to if ($type = = 0) {/ / split the numeric string of decimal places into an array $decimalArr = str_split ($amountArr [1], 1); / / replace the corner into uppercase Chinese characters. If 0, if ($decimalArr [0]! = 0) {$result = $result. $digital [$decimalArr [0]]. Replace 'Jiao';} / / with uppercase Chinese characters. If 0, if ($decimalArr [1]! = 0) {$result = $result. $digital [$decimalArr [1]]. Else {$result = $result. 'whole';} return $result;}
After reading this article, I believe you have some understanding of "how to convert php into Chinese". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.