{
int64 tmpNum = any2int64(abs(_num));
str tmpStr = strfmt("%1",tmpNum);
int lenStr = strLen(tmpStr), i, j;
real remainAmount = abs(_num) - tmpNum;
int tmp = decround(abs(remainAmount),2)*100;
str trillionTxt = "";
str billionTxt = "";
str millionTxt = "";
str thousandTxt = "";
str hundredTxt = "";
str remainTxt = "";
VASUtils vasUtil = new VASUtils();
;
if (_num == 0)
return "Không";
If (remainAmount != 0)
remainTxt = strfmt(" và %1/%2",tmp,100);
else
remainTxt = "";
for (i = lenStr; i >= 1; i --)
{
j ++;
if (i > 12 && i <= 15)
trillionTxt = trillionTxt + substr(tmpStr,j,1);
if (i > 9 && i <= 12)
billionTxt = billionTxt + substr(tmpStr,j,1);
if (i > 6 && i <= 9)
millionTxt = millionTxt + substr(tmpStr,j,1);
if (i > 3 && i <= 6)
thousandTxt = thousandTxt + substr(tmpStr,j,1);
if (i <= 3)
hundredTxt = hundredTxt + substr(tmpStr,j,1);
}
return str2Capital(strltrim(strRtrim(vasUtil.trillion(trillionTxt)
+ vasUtil.billion(billionTxt)
+ vasUtil.million(millionTxt)
+ vasUtil.thousand(thousandTxt)
+ vasUtil.hundred(hundredTxt)
+ remainTxt)));
}
Protected str billion(str billion)
{
;
if (billion == "000" || billion == "")
return "";
else
return this.hundred(billion) + " Tỷ ";
}
Protected str hundred(str hundred)
{
str txt = "", tmpTxt;
int i, tmplen = strlen(hundred);
;
if (hundred == "000")
return "";
if ((tmplen == 3) && (substr(hundred,2,2) == "00"))
{
return this.rawStr(substr(hundred,1,1)) + " Trăm";
}
else if (tmplen == 2)
{
if (substr(hundred,1,1) == "1")
{
if (substr(hundred,2,1) == "0")
return " Mười";
else
return " Mười " + this.rawStr(substr(hundred,2,1));
}
else
{
if (substr(hundred,2,1) == "0")
return this.rawStr(substr(hundred,1,1)) + " Mươi";
else if (substr(hundred,2,1) == "1")
return this.rawStr(substr(hundred,1,1)) + " Mươi " + "Mốt";
else
{
if (substr(hundred,2,1) == "5")
return this.rawStr(substr(hundred,1,1)) + " Mươi " + "Lăm";
else
return this.rawStr(substr(hundred,1,1)) + " Mươi " + this.rawStr(substr(hundred,2,1));
}
}
}
else if (tmplen == 1)
{
return this.rawStr(hundred);
}
for (i = 1; i <= strlen(hundred); i++)
{
tmpTxt = subStr(hundred,i,1);
if (i == 1)
txt = this.rawStr(tmpTxt) + " Trăm";
if (i == 2)
{
if (str2int(tmpTxt) >= 2)
{
txt = txt + " " + this.rawStr(tmpTxt) + " Mươi";
}
else
{
if (tmpTxt == "0")
txt = txt + " Lẻ";
else
txt = txt + " Mười";
}
}
if (i == 3)
{
if (tmpTxt == "0")
txt = txt;
else if (tmpTxt == "1")
{
if (substr(hundred,strLen(hundred)-1,1) == "0" || substr(hundred,strLen(hundred)-1,1) == "1")
txt = txt + " Một";
else
txt = txt + " Mốt";
}
else if (tmpTxt == "5" && subStr(hundred,2,1) != "0")
txt = txt + " Lăm";
else
txt = txt + " " + this.rawStr(tmpTxt);
}
}
return txt;
}
Protected str million(str million)
{
;
if (million == "000" || million == "")
return "";
else
return this.hundred(million) + " Triệu ";
}
Protected str rawStr(str tenth)
{
str ret;
;
switch (tenth)
{
case "0":
ret = "Không";
break;
case "1":
ret = "Một";
break;
case "2":
ret = "Hai";
break;
case "3":
ret = "Ba";
break;
case "4":
ret = "Bốn";
break;
case "5":
ret = "Năm";
break;
case "6":
ret = "Sáu";
break;
case "7":
ret = "Bảy";
break;
case "8":
ret = "Tám";
break;
case "9":
ret = "Chín";
break;
case "10":
ret = "Mười";
break;
}
return ret;
}
Protected str thousand(str thousand)
{
;
if (thousand == "000" || thousand == "")
return "";
else
return this.hundred(thousand) + " Ngàn ";
}
Protected str trillion(str trillion)
{
;
if (trillion == "000" || trillion == "")
return "";
else
return this.hundred(trillion) + " Ngàn tỷ ";
}