数字转换中文
php代码
<?php class TransFormNumber{ public $chinaData = array('1'=>'壹','2'=>'贰','3'=>'叁','4'=>'肆','5'=>'伍','6'=>'陆','7'=>'柒','8'=>'捌','9'=>'玖'); public $chinaDataInt = array('1'=>'元','2'=>'拾','3'=>'佰','4'=>'仟','5'=>'万','6'=>'拾','7'=>'佰','8'=>'仟','9'=>'亿','10'=>'拾','11'=>'佰','12'=>'仟','13'=>'万'); public $chinaDataFloat = array('1'=>'角','2'=>'分'); private $Intnumber; // string private $Floatnumber; // string public $error = array('0'=>'零','def'=>'数据格式不支持'); public function __construct($intnumber,$floatnumber){ $this->Intnumber = $intnumber; $this->Floatnumber = $floatnumber; } /*13位整数*/ public function getTransInt(){ $this->Intnumber = intval($this->Intnumber); $len = strlen($this->Intnumber); if($len > 13){ return $this->errorNotice(1); } if($this->Intnumber == 0){ return $this->errorNotice('def'); } $intData = strrev(substr($this->Intnumber,0,$len)); $data = $this->setTransInt($intData,$len); krsort($data); $str = rtrim(join($data,''),'零'); if(substr($this->Intnumber,$len-1,1) == 0){ $str.='元'; } unset($data); return $str; } public function getTransFloat(){ return $this->setTransFloat($this->Floatnumber,strlen($this->Floatnumber)); } private function setTransInt($intData,$pos){ for($i=0;$i<$pos;$i++){ $oneData = substr($intData,$i,1); if(($i == 4 || ($i%8) == 4) && $oneData == 0){ if(substr($intData,$i+1,1) == 0 && substr($intData,$i+2,1) == 0 && substr($intData,$i+3,1) == 0){ if(substr($intData,$i-1,1) == 0){ continue; }else{ $data[] = '零'; } }else{ $data[] = '万'; continue; } continue; } if($i%8 == 0 && $i != 0 && $oneData == 0){ $data[] = '亿'; } if($oneData == 0){ if(($i == 4 || $i == 7)){ if((substr($intData,$i-1,1) ==0)){ continue; }else{ $data[] = '零'; } }else{ if(substr($intData,$i-1,1) !=0 && $i !=3 && $i != 8){ $data[] = '零'; }else{ if($i == 3 && substr($intData,$i,1) == 0 && substr($intData,$i-1,1) != 0){ $data[] = '零'; } } } }else{ $data[] = $this->chinaData[$oneData].$this->chinaDataInt[$i+1]; } } unset($intData,$oneData,$i); return $data; } //紧支持两位小数 private function setTransFloat($floatData,$pos){ if($pos > 2){ return $this->errorNotice('def'); } if($floatData{0} == 0){ $data[] = '零'; }else{ $data[] = $this->chinaData[$floatData{0}].$this->chinaDataFloat[1]; } if($floatData{1} != 0 ){ $data[] = $this->chinaData[$floatData{1}].$this->chinaDataFloat[2]; } return implode('',$data); } public function errorNotice($error){ return $this->error[$error]; } } $num = new TransFormNumber('100228030','80'); echo $num->getTransInt(); echo $num->getTransFloat();
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사
<garden> : 정원 재배 - 완전한 돌연변이 가이드
4 몇 주 전
By DDD
<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
1 몇 달 전
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
<exp exp> 모호한 : 원정 33- 완벽한 크로마 촉매를 얻는 방법
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)