ActionScript 3 AS3将数字转换为字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3将数字转换为字符串相关的知识,希望对你有一定的参考价值。
function fNumToWord(vNum:int):String
{
var mWords:Array = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"];
mWords[30] = "Thirty";
mWords[40] = "Forty";
mWords[50] = "Fifty";
mWords[60] = "Sixty";
mWords[70] = "Seventy";
mWords[80] = "Eighty";
mWords[90] = "Ninety";
var v : int;
var vWord : String;
var vString : String;
vWord = "";
if (vNum < 21) {
vWord += mWords[vNum];
}else if (vNum < 100) {
vWord += mWords[10 * Math.floor(vNum / 10)];
v = vNum % 10;
vString = (String(vNum).substr( -1) == "0") ? " " : "-";
if (v > 0) {
vWord += vString + mWords[v];
}
} else if (vNum < 1000) {
vString = (String(vNum).substr( -2) == "00") ? " Hundred" : " Hundred and";
vWord += mWords[Math.floor(vNum / 100)] + vString;
v = vNum % 100;
if (v > 0) {
vWord += " " + fNumToWord(v);
}
} else if (vNum < 1000000) {
vString = (String(vNum).substr( -3) == "000") ? " Thousand" : " Thousand and";
vWord += fNumToWord(Math.floor(vNum / 1000)) + vString;
v = vNum % 1000;
if (v > 0) {
vWord += " ";
if (v < 100)
vWord += " ";
vWord += fNumToWord(v);
}
} else {
vString = (String(vNum).substr( -6) == "000000") ? " Million" : " Million and";
vWord += fNumToWord(Math.floor(vNum / 1000000)) + vString;
v = vNum % 1000000;
if (v > 0) {
vWord += " ";
if (v < 100) {
vWord += " ";
}
vWord += fNumToWord(v);
}
}
return vWord;
}
以上是关于ActionScript 3 AS3将数字转换为字符串的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3将DisplayObject转换为黑白
ActionScript 3 AS3将百分比转换为值
ActionScript 3 AS3按名称将对象转换为类
ActionScript 3 AS3将整数转换为二进制值
ActionScript 3 将Java DateTime转换为AS3日期
ActionScript 3 AS3将字符串转换为函数名称