


A supplement to the class for converting numbers into Chinese written by Alpha.Z. I was bored last night_PHP Tutorial
Removed some redundant zeros "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); //var $basical=array(0=>"zero","one","two","three","four","五","鲁","七","八","九" ); var $advanced=array(1=>"十","百","千"); //var $advanced=array(1=>"十","百","千"); var $ top=array(1=>"10,000","100 million"); var $level; // Use 4 digits as one level // First implement the conversion function of numbers below 10,000 ParseNumber($number) { if ($number >999999999999) // Can only process up to 100 billion. return "The number is too large to handle. Sorry!"; if ($number==0) return "zero"; for($this->level=0;$number>0.0001;$this->level++,$number= floor($number / 10000)) { // For Chinese, it should be a group of 4 digits. // The four variables correspond to ones, tens, hundreds, and thousands respectively. $n1=substr($number,-1,1); if($number>9) $n2=substr($number,-2,1); else $n2=0; if($number>99) $n3 =substr($number,-3,1); else $n3=0; if($number>999) $n4=substr($number,-4,1); else $n4=0; if($n4) $parsed[$this->level].=$this->basical[$n4].$this->advanced[3]; else if(($number/10000)>=1) // Thousands digit is 0, If the value is greater than 9999 $parsed[$this->level].="zero"; if($n3) $parsed[$this->level].=$this->basical[$n3].$this-> advanced[2]; else if(!ereg("zero$",$parsed[$this->level]) && ($number / 1000)>=1) // There are no two consecutive "zeros" $ parsed[$this->level].="zero"; if($n2) $parsed[$this->level].=$this->basical[$n2].$this->advanced[1]; else if(!ereg("zero$",$parsed[$this->level]) && ($number / 100)>=1) // There will be no two consecutive "zeros" $parsed[$this-> level].="zero"; if($n1) $parsed[$this->level].=$this->basical[$n1]; if($parsed[$this->level]!="zero" ) { if(ereg("zero$",$parsed[$this->level])) $parsed[$this->level]=substr($parsed[$this->level],0,strlen($parsed [$this->level])-2); if($this->level>0) $result=$parsed[$this->level].$this->top[$this->level].$result ; else $result=$parsed[$this->level].$result; } } //for($this->level-=1;$this->level>=0;$this->level--) //{ // $result.=$parsed[$this->level].$this->top[$this->level]; //} //if(ereg("zero$",$result)) // $result=substr($result,0,strlen($result)-2); return $result; } }; $c=new ChineseNumber(); echo $c->ParseNumber(100000000001); ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

How to convert full-width English letters into half-width letters In daily life and work, sometimes we encounter situations where we need to convert full-width English letters into half-width letters, such as when entering computer passwords, editing documents, or designing layouts. Full-width English letters and numbers refer to characters with the same width as Chinese characters, while half-width English letters refer to characters with a narrower width. In actual operation, we need to master some simple methods to convert full-width English letters into half-width letters so that we can process text and numbers more conveniently. 1. Full-width English letters and half-width English letters

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

ASCII value conversion in PHP is a problem often encountered in programming. ASCII (American Standard Code for Information Interchange) is a standard encoding system for converting characters into numbers. In PHP, we often need to convert between characters and numbers through ASCII code. This article will introduce how to convert ASCII values in PHP and give specific code examples. 1. Change the characters

When using a computer to input English, sometimes we encounter the difference between full-width English letters and half-width English letters. Full-width English letters refer to the characters input by pressing the Shift key and the English letter key combination when the input method is Chinese mode. They occupy a full-width character width. Half-width English letters refer to characters input directly when the input method is English mode, and they occupy half a character width. In some cases, we may need to convert full-width English letters to half-width letters. Here is a simple tutorial: First, open a text editor or any

In PHP programming, spaces are often encountered when processing strings, including Chinese spaces. In actual development, we often use the trim function to remove spaces at both ends of a string, but the processing of Chinese spaces is relatively complicated. This article will introduce how to use the trim function in PHP to process Chinese spaces and provide specific code examples. First, let us understand the types of Chinese spaces. In Chinese, spaces include not only common English spaces (space), but also some other special spaces.
