Have you ever thought about converting the calculation results of the number format into Chinese character format? Some people may ask, "Why do you need to convert? The number form is pretty good?" But when the number is very long, it is not easy to read. Even if there are thousands of separators, it is not easy to say, because this symbol is convenient for English lines and is not suitable for our reading. Then write a function yourself to complete this task.
Add the following code to your web page, and you can implement the above function by calling the num2chi() function. Come and give it a try. In order to understand this code, I will add detailed annotations below. Please don’t be so arrogant, ^_^.
//----------------------FUNCTION BEGIN-----------------------------
//-------------------------------------------
//Function name: num2chi()
//Three numbers: a number
//Return value: a string
//Function: Turn long lists of difficult-to-read numbers into Chinese characters that are read out casually
//author:
//Site Point: HTTP://
//-------------------------------------------
function num2chi(result) {
var chiresult = ""; //Define the return value parameter chiresult as a character form
result = (); //Convert result to character form
result = ();
resultlen = ; //Define the length of resultlen as result
tempresult = result; //Define the intermediate variable tempresult
for (i=1;i<=resultlen;i++) //Replace all numbers in the string tempresult with Chinese characters
{
tempresult = ("1","1");
tempresult = ("2","two");
tempresult = ("3","three");
tempresult = ("4","four");
tempresult = ("5","five");
tempresult = ("6","six");
tempresult = ("7","7");
tempresult = ("8","8");
tempresult = ("9","9");
tempresult = ("0","zero");
tempresult = (".","point");
tempresult = ("e+","power");
}
while(("zero zero")!=-1) //Avoid "zero zero" in the string tempresult, but cannot change the string length
{
tempresult = ("zero zero","bit zero");
}
resultlen = ; //Confirm the length of tempresult again, because "e+"->"power" will cause length change
for (i=1,j=1,k=1;i<=resultlen;i++) //Start conversion, i is the digit confirmation parameter, j is the "ten hundred thousand" confirmation parameter, k is the "trillion" confirmation parameter
{
//Prevent the last digit from zero, such as eight pick zero, two pick zero ten thousand
if ((resultlen-1)=="zero"&&i==1)
chiresult = "bit";
else if ((resultlen-i)=="zero"&&j==1)
chiresult = "bit" + chiresult;
//--------------------------------
//Avoid using "power" and "points" as actual digits, and recounting the unit confirmation variables
else if ((resultlen-i)=="power")
{
j=1;k=1;chiresult = (resultlen-i) + chiresult;continue;
}
else if ((resultlen-i)=="point")
{
j=1;k=1;chiresult = (resultlen-i) + chiresult;continue;
}
//--------------------------------------
else
chiresult = (resultlen-i) + chiresult;
//Add numeric units
if ((resultlen-i-1)!="bit"&&(resultlen-i-1)!="zero"&&(resultlen-i-1)!="power")
{
if (j==1&&i<resultlen) chiresult = "Check" + chiresult;
else if (j==2&&i<resultlen) chiresult = "hundred" + chiresult;
else if (j==3&&i<resultlen) chiresult = "thousand" + chiresult;
}
if (j==4&&i<resultlen) j=0;
if (k==4&&i<resultlen&&(resultlen-i-1)!="power") chiresult = "10,000" + chiresult;
else if (k==8&&i<resultlen&&(resultlen-i-1)!="power") {k=0;chiresult = "100 million" + chiresult;}
//-----------
j++;k++;
}
while(("bit")!=-1) //Avoid "bit" appearing in the string chiresult
{
chiresult = ("bit","");
}
if ((0,2)=="Use it") //Avoid "Use it" and other situations such as "Use it"
chiresult = (1,);
//The numbers after the power and decimal points should be read directly without units
if (("power")>=0&&("point")>=0)
{
rebegin = (0,("point"));
relast = (("power"),);
remid = (("point"),("power"));
for (i=1;i<=;i++)
{
remid = ("Select","");
remid = ("hundred","");
remid = ("thousand","");
remid = ("Wan","");
remid = ("billion","");
}
chiresult = rebegin + remid + relast;
}
else if (("power")<0&&("point")>=0)
{
rebegin = (0,("point"));
relast = (("point"),);
for (i=1;i<=;i++)
{
relast = ("Select","");
relast = ("hundred","");
relast = ("thousand","");
relast = ("Wan","");
relast = ("billion","");
}
chiresult = rebegin + relast;
}
if (("power")>=0) //Replace "power" with "multiple by pick", so that you can read it directly
{
chiresult = ("power","multiple by pick");
chiresult = chiresult + "power";
}
return chiresult;
}
//----------------------FUNCTION END-------------------------------
Put the following two statements into the script block and try to run them to see if the result is correct. In addition, you can visit my homepage There is a lottery page in the leisure square, which is implemented using this code. Welcome.
hi='4648000567542450084.16415846E+766600050';
(hi+"<br>"+num2chi(hi));
Add the following code to your web page, and you can implement the above function by calling the num2chi() function. Come and give it a try. In order to understand this code, I will add detailed annotations below. Please don’t be so arrogant, ^_^.
//----------------------FUNCTION BEGIN-----------------------------
//-------------------------------------------
//Function name: num2chi()
//Three numbers: a number
//Return value: a string
//Function: Turn long lists of difficult-to-read numbers into Chinese characters that are read out casually
//author:
//Site Point: HTTP://
//-------------------------------------------
function num2chi(result) {
var chiresult = ""; //Define the return value parameter chiresult as a character form
result = (); //Convert result to character form
result = ();
resultlen = ; //Define the length of resultlen as result
tempresult = result; //Define the intermediate variable tempresult
for (i=1;i<=resultlen;i++) //Replace all numbers in the string tempresult with Chinese characters
{
tempresult = ("1","1");
tempresult = ("2","two");
tempresult = ("3","three");
tempresult = ("4","four");
tempresult = ("5","five");
tempresult = ("6","six");
tempresult = ("7","7");
tempresult = ("8","8");
tempresult = ("9","9");
tempresult = ("0","zero");
tempresult = (".","point");
tempresult = ("e+","power");
}
while(("zero zero")!=-1) //Avoid "zero zero" in the string tempresult, but cannot change the string length
{
tempresult = ("zero zero","bit zero");
}
resultlen = ; //Confirm the length of tempresult again, because "e+"->"power" will cause length change
for (i=1,j=1,k=1;i<=resultlen;i++) //Start conversion, i is the digit confirmation parameter, j is the "ten hundred thousand" confirmation parameter, k is the "trillion" confirmation parameter
{
//Prevent the last digit from zero, such as eight pick zero, two pick zero ten thousand
if ((resultlen-1)=="zero"&&i==1)
chiresult = "bit";
else if ((resultlen-i)=="zero"&&j==1)
chiresult = "bit" + chiresult;
//--------------------------------
//Avoid using "power" and "points" as actual digits, and recounting the unit confirmation variables
else if ((resultlen-i)=="power")
{
j=1;k=1;chiresult = (resultlen-i) + chiresult;continue;
}
else if ((resultlen-i)=="point")
{
j=1;k=1;chiresult = (resultlen-i) + chiresult;continue;
}
//--------------------------------------
else
chiresult = (resultlen-i) + chiresult;
//Add numeric units
if ((resultlen-i-1)!="bit"&&(resultlen-i-1)!="zero"&&(resultlen-i-1)!="power")
{
if (j==1&&i<resultlen) chiresult = "Check" + chiresult;
else if (j==2&&i<resultlen) chiresult = "hundred" + chiresult;
else if (j==3&&i<resultlen) chiresult = "thousand" + chiresult;
}
if (j==4&&i<resultlen) j=0;
if (k==4&&i<resultlen&&(resultlen-i-1)!="power") chiresult = "10,000" + chiresult;
else if (k==8&&i<resultlen&&(resultlen-i-1)!="power") {k=0;chiresult = "100 million" + chiresult;}
//-----------
j++;k++;
}
while(("bit")!=-1) //Avoid "bit" appearing in the string chiresult
{
chiresult = ("bit","");
}
if ((0,2)=="Use it") //Avoid "Use it" and other situations such as "Use it"
chiresult = (1,);
//The numbers after the power and decimal points should be read directly without units
if (("power")>=0&&("point")>=0)
{
rebegin = (0,("point"));
relast = (("power"),);
remid = (("point"),("power"));
for (i=1;i<=;i++)
{
remid = ("Select","");
remid = ("hundred","");
remid = ("thousand","");
remid = ("Wan","");
remid = ("billion","");
}
chiresult = rebegin + remid + relast;
}
else if (("power")<0&&("point")>=0)
{
rebegin = (0,("point"));
relast = (("point"),);
for (i=1;i<=;i++)
{
relast = ("Select","");
relast = ("hundred","");
relast = ("thousand","");
relast = ("Wan","");
relast = ("billion","");
}
chiresult = rebegin + relast;
}
if (("power")>=0) //Replace "power" with "multiple by pick", so that you can read it directly
{
chiresult = ("power","multiple by pick");
chiresult = chiresult + "power";
}
return chiresult;
}
//----------------------FUNCTION END-------------------------------
Put the following two statements into the script block and try to run them to see if the result is correct. In addition, you can visit my homepage There is a lottery page in the leisure square, which is implemented using this code. Welcome.
hi='4648000567542450084.16415846E+766600050';
(hi+"<br>"+num2chi(hi));