Bf [2887756] - AmountInWords_VI
http://sourceforge.net/tracker/?func=detail&atid=883808&aid=2887756&group_id=176962
This commit is contained in:
parent
7c3ef24638
commit
3bef94df78
|
|
@ -16,6 +16,9 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.util;
|
package org.compiere.util;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.taskdefs.Length;
|
||||||
|
import org.python.modules.math;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount in Words for Vietnamese
|
* Amount in Words for Vietnamese
|
||||||
|
|
@ -37,23 +40,29 @@ package org.compiere.util;
|
||||||
* 5 - "năm" but 15 = "mười lăm"
|
* 5 - "năm" but 15 = "mười lăm"
|
||||||
*
|
*
|
||||||
* TEST RESULTS:
|
* TEST RESULTS:
|
||||||
* 0.23 = Không 23/100
|
* 0.23 = không phẩy hai mươi ba
|
||||||
* 1.23 = Một 23/100
|
* 1.23 = một phẩy hai mươi ba
|
||||||
* 12.345 = Mười hai 345/100
|
* 12,345 = mười hai nghìn ba trăm bốn mươi lăm
|
||||||
* 103.45 = Một Trăm linh Ba 45/100
|
* 103.45 = một trăm linh ba phẩy bốn mươi lăm
|
||||||
* 114.45 = Một Trăm Mười bốn 45/100
|
* 114,45 = một trăm mười bốn phẩy bốn mươi lăm
|
||||||
* 123.45 = Một Trăm Hai mươi ba 45/100
|
* 123.45 = một trăm hai mươi ba phẩy bốn mươi lăm
|
||||||
* 1023.45 = Một Nghìn không trăm Hai mươi ba 45/100
|
* 1023.45 = một nghìn không trăm hai mươi ba phẩy bốn mươi lăm
|
||||||
* 1234.56 = Một Nghìn Hai Trăm Ba mươi bốn 56/100
|
* 1234.56 = một nghìn hai trăm ba mươi bốn phẩy năm mươi sáu
|
||||||
* 12345.78 = Mười hai Nghìn Ba Trăm Bốn mươi lăm 78/100
|
* 12345.78 = mười hai nghìn ba trăm bốn mươi lăm phẩy bẩy mươi tám
|
||||||
* 103457.89 = Một Trăm linh Ba Nghìn Bốn Trăm Năm mươi bẩy 89/100
|
* 100457.89 = một trăm nghìn bốn trăm năm mươi bẩy phẩy tám mươi chín
|
||||||
* 1,234,578.90 = Một Triệu Hai Trăm Ba mươi bốn Nghìn Năm Trăm Bẩy mươi tám 90/100
|
* 100,234,578.90 = một trăm triệu hai trăm ba mươi bốn nghìn năm trăm bẩy mươi tám phẩy chín mươi
|
||||||
* 1,034,578.90 = Một Triệu không trăm Ba mươi bốn Nghìn Năm Trăm Bẩy mươi tám 90/100
|
* 12,034,578.90 = mười hai triệu không trăm ba mươi bốn nghìn năm trăm bẩy mươi tám phẩy chín mươi
|
||||||
* 1,004,008.90 = Một Triệu không trăm linh Bốn Nghìn không trăm linh Tám 90/100
|
* 103,004,008.90 = một trăm linh ba triệu không trăm linh bốn nghìn không trăm linh tám phẩy chín mươi
|
||||||
* 1,201,034,578.90 = Một Tỉ Hai Trăm linh Một Triệu không trăm Ba mươi bốn Nghìn Năm Trăm Bẩy mươi tám 90/100
|
* 1,201,034,578.90 = một tỉ hai trăm linh một triệu không trăm ba mươi bốn nghìn năm trăm bẩy mươi tám phẩy chín mươi
|
||||||
|
* 12,201,034,578.90 = mười hai tỉ hai trăm linh một triệu không trăm ba mươi bốn nghìn năm trăm bẩy mươi tám phẩy chín mươi
|
||||||
|
* 10220134578 = mười tỉ hai trăm hai mươi triệu một trăm ba mươi bốn nghìn năm trăm bẩy mươi tám
|
||||||
|
* 1.093.201.034.578 = một nghìn không trăm chín mươi ba tỉ hai trăm linh một triệu không trăm ba mươi bốn nghìn năm trăm bẩy mươi tám
|
||||||
|
* 100,932,010,345,780 = một trăm nghìn chín trăm ba mươi hai tỉ mười triệu ba trăm bốn mươi lăm nghìn bẩy trăm tám mươi
|
||||||
|
* 109.320.103,48 = một trăm linh chín triệu ba trăm hai mươi nghìn một trăm linh ba phẩy bốn mươi tám
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
* @version $Id: AmtInWords_VI.java,v 1.0 2009/03/30 23:03:00$
|
* @version $Id: AmtInWords_VI.java,v 1.1 2009/04/08 00:28:00$
|
||||||
*/
|
*/
|
||||||
public class AmtInWords_VI implements AmtInWords
|
public class AmtInWords_VI implements AmtInWords
|
||||||
{
|
{
|
||||||
|
|
@ -68,130 +77,115 @@ public class AmtInWords_VI implements AmtInWords
|
||||||
/** Thousands plus */
|
/** Thousands plus */
|
||||||
private static final String[] majorNames = {
|
private static final String[] majorNames = {
|
||||||
"",
|
"",
|
||||||
" Nghìn ",
|
" nghìn ",
|
||||||
" Triệu ",
|
" triệu ",
|
||||||
" Tỉ ",
|
" tỉ ",
|
||||||
" Nghìn tỉ ",
|
" nghìn ",
|
||||||
" Triệu tỉ ",
|
" triệu ",
|
||||||
" Tỉ tỉ "
|
" tỉ "
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Ten to Ninety *///No necessary anymore since we have # to 99
|
|
||||||
/* private static final String[] tensNames = {
|
|
||||||
"",
|
|
||||||
"Mười",
|
|
||||||
"Hai mươi",
|
|
||||||
"Ba mươi",
|
|
||||||
"Bốn mươi",
|
|
||||||
"Năm mươi",
|
|
||||||
"Sáu mươi",
|
|
||||||
"Bảy mươi",
|
|
||||||
"Tám mươi",
|
|
||||||
"Chín mươi"
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
/** numbers to 99 */
|
/** numbers to 99 */
|
||||||
private static final String[] numNames = {
|
private static final String[] numNames = {
|
||||||
"Không",
|
"",
|
||||||
"Một",
|
"một",
|
||||||
"Hai",
|
"hai",
|
||||||
"Ba",
|
"ba",
|
||||||
"Bốn",
|
"bốn",
|
||||||
"Năm",
|
"năm",
|
||||||
"Sáu",
|
"sáu",
|
||||||
"Bẩy",
|
"bẩy",
|
||||||
"Tám",
|
"tám",
|
||||||
"Chín",
|
"chín",
|
||||||
"Mười",
|
"mười",
|
||||||
"Mười một",
|
"mười một",
|
||||||
"Mười hai",
|
"mười hai",
|
||||||
"Mười ba",
|
"mười ba",
|
||||||
"Mười bốn",
|
"mười bốn",
|
||||||
"Mười lăm", //list it here so no programming is needed. See note 3,4
|
"mười lăm", //list it here so no programming is needed. see note 3,4
|
||||||
"Mười sáu",
|
"mười sáu",
|
||||||
"Mười bẩy",
|
"mười bẩy",
|
||||||
"Mười tám",
|
"mười tám",
|
||||||
"Mười chín",
|
"mười chín",
|
||||||
"Hai mươi",
|
"hai mươi",
|
||||||
"Hai mươi mốt", //list it here so no programming is needed. See note 3,4
|
"hai mươi mốt", //list it here so no programming is needed. see note 3,4
|
||||||
"Hai mươi hai",
|
"hai mươi hai",
|
||||||
"Hai mươi ba",
|
"hai mươi ba",
|
||||||
"Hai mươi bốn",
|
"hai mươi bốn",
|
||||||
"Hai mươi lăm",//list it here so no programming is needed. See note 3,4
|
"hai mươi lăm",//list it here so no programming is needed. see note 3,4
|
||||||
"Hai mươi sáu",
|
"hai mươi sáu",
|
||||||
"Hai mươi bẩy",
|
"hai mươi bẩy",
|
||||||
"Hai mươi tám",
|
"hai mươi tám",
|
||||||
"Hai mươi chín",
|
"hai mươi chín",
|
||||||
"Ba mươi",
|
"ba mươi",
|
||||||
"Ba mươi mốt",//list it here so no programming is needed. See note 3,4
|
"ba mươi mốt",//list it here so no programming is needed. see note 3,4
|
||||||
"Ba mươi hai",
|
"ba mươi hai",
|
||||||
"Ba mươi ba",
|
"ba mươi ba",
|
||||||
"Ba mươi bốn",
|
"ba mươi bốn",
|
||||||
"Ba mươi lăm",//list it here so no programming is needed. See note 3,4
|
"ba mươi lăm",//list it here so no programming is needed. see note 3,4
|
||||||
"Ba mươi sáu",
|
"ba mươi sáu",
|
||||||
"Ba mươi bẩy",
|
"ba mươi bẩy",
|
||||||
"Ba mươi tám",
|
"ba mươi tám",
|
||||||
"Ba mươi chín",
|
"ba mươi chín",
|
||||||
"Bốn mươi",
|
"bốn mươi",
|
||||||
"Bốn mươi mốt",//list it here so no programming is needed. See note 3,4
|
"bốn mươi mốt",//list it here so no programming is needed. see note 3,4
|
||||||
"Bốn mươi hai",
|
"bốn mươi hai",
|
||||||
"Bốn mươi ba",
|
"bốn mươi ba",
|
||||||
"Bốn mươi bốn",
|
"bốn mươi bốn",
|
||||||
"Bốn mươi lăm",//list it here so no programming is needed. See note 3,4
|
"bốn mươi lăm",//list it here so no programming is needed. see note 3,4
|
||||||
"Bốn mươi sáu",
|
"bốn mươi sáu",
|
||||||
"Bốn mươi bẩy",
|
"bốn mươi bẩy",
|
||||||
"Bốn mươi tám",
|
"bốn mươi tám",
|
||||||
"Bốn mươi chín",
|
"bốn mươi chín",
|
||||||
"Năm mươi",
|
"năm mươi",
|
||||||
"Năm mươi mốt",//list it here so no programming is needed. See note 3,4
|
"năm mươi mốt",//list it here so no programming is needed. see note 3,4
|
||||||
"Năm mươi hai",
|
"năm mươi hai",
|
||||||
"Năm mươi ba",
|
"năm mươi ba",
|
||||||
"Năm mươi bốn",
|
"năm mươi bốn",
|
||||||
"Năm mươi lăm",//list it here so no programming is needed. See note 3,4
|
"năm mươi lăm",//list it here so no programming is needed. see note 3,4
|
||||||
"Năm mươi sáu",
|
"năm mươi sáu",
|
||||||
"Năm mươi bẩy",
|
"năm mươi bẩy",
|
||||||
"Năm mươi tám",
|
"năm mươi tám",
|
||||||
"Năm mươi chín",
|
"năm mươi chín",
|
||||||
"Sáu mươi",
|
"sáu mươi",
|
||||||
"Sáu mươi mốt",//list it here so no programming is needed. See note 3,4
|
"sáu mươi mốt",//list it here so no programming is needed. see note 3,4
|
||||||
"Sáu mươi hai",
|
"sáu mươi hai",
|
||||||
"Sáu mươi ba",
|
"sáu mươi ba",
|
||||||
"Sáu mươi bốn",
|
"sáu mươi bốn",
|
||||||
"Sáu mươi lăm",//list it here so no programming is needed. See note 3,4
|
"sáu mươi lăm",//list it here so no programming is needed. see note 3,4
|
||||||
"Sáu mươi sáu",
|
"sáu mươi sáu",
|
||||||
"Sáu mươi bẩy",
|
"sáu mươi bẩy",
|
||||||
"Sáu mươi tám",
|
"sáu mươi tám",
|
||||||
"Sáu mươi chín",
|
"sáu mươi chín",
|
||||||
"Bẩy mươi",
|
"bẩy mươi",
|
||||||
"Bẩy mươi mốt",//list it here so no programming is needed. See note 3,4
|
"bẩy mươi mốt",//list it here so no programming is needed. See note 3,4
|
||||||
"Bẩy mươi hai",
|
"bẩy mươi hai",
|
||||||
"Bẩy mươi ba",
|
"bẩy mươi ba",
|
||||||
"Bẩy mươi bốn",
|
"bẩy mươi bốn",
|
||||||
"Bẩy mươi lăm",//list it here so no programming is needed. See note 3,4
|
"bẩy mươi lăm",//list it here so no programming is needed. See note 3,4
|
||||||
"Bẩy mươi sáu",
|
"bẩy mươi sáu",
|
||||||
"Bẩy mươi bẩy",
|
"bẩy mươi bẩy",
|
||||||
"Bẩy mươi tám",
|
"bẩy mươi tám",
|
||||||
"Bẩy mươi chín",
|
"bẩy mươi chín",
|
||||||
"Tám mươi",
|
"tám mươi",
|
||||||
"Tám mươi mốt",//list it here so no programming is needed. See note 3,4
|
"tám mươi mốt",//list it here so no programming is needed. See note 3,4
|
||||||
"Tám mươi hai",
|
"tám mươi hai",
|
||||||
"Tám mươi ba",
|
"tám mươi ba",
|
||||||
"Tám mươi bốn",
|
"tám mươi bốn",
|
||||||
"Tám mươi lăm",//list it here so no programming is needed. See note 3,4
|
"tám mươi lăm",//list it here so no programming is needed. See note 3,4
|
||||||
"Tám mươi sáu",
|
"tám mươi sáu",
|
||||||
"Tám mươi bẩy",
|
"tám mươi bẩy",
|
||||||
"Tám mươi tám",
|
"tám mươi tám",
|
||||||
"Tám mươi chín",
|
"tám mươi chín",
|
||||||
"Chín mươi",
|
"chín mươi",
|
||||||
"Chín mươi mốt",//list it here so no programming is needed. See note 3,4
|
"chín mươi mốt",//list it here so no programming is needed. See note 3,4
|
||||||
"Chín mươi hai",
|
"chín mươi hai",
|
||||||
"Chín mươi ba",
|
"chín mươi ba",
|
||||||
"Chín mươi bốn",
|
"chín mươi bốn",
|
||||||
"Chín mươi lăm",//list it here so no programming is needed. See note 3,4
|
"chín mươi lăm",//list it here so no programming is needed. See note 3,4
|
||||||
"Chín mươi sáu",
|
"chín mươi sáu",
|
||||||
"Chín mươi bẩy",
|
"chín mươi bẩy",
|
||||||
"Chín mươi tám",
|
"chín mươi tám",
|
||||||
"Chín mươi chín"
|
"chín mươi chín"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -205,14 +199,14 @@ public class AmtInWords_VI implements AmtInWords
|
||||||
String soFar = "";
|
String soFar = "";
|
||||||
// Below 10
|
// Below 10
|
||||||
if (number % 100 < 10 && number > 100)
|
if (number % 100 < 10 && number > 100)
|
||||||
soFar = "linh "; //see Note 1
|
soFar = " linh "; //see Note 1
|
||||||
soFar = soFar + numNames[number % 100];
|
soFar = soFar + numNames[number % 100];
|
||||||
number /= 100;
|
number /= 100;
|
||||||
|
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
return soFar;
|
return soFar;
|
||||||
|
|
||||||
return numNames[number] + " Trăm " + soFar;
|
return numNames[number] + " trăm " + soFar;
|
||||||
} // convertLessThanOneThousand
|
} // convertLessThanOneThousand
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -225,13 +219,13 @@ public class AmtInWords_VI implements AmtInWords
|
||||||
/* special case */
|
/* special case */
|
||||||
if (number == 0)
|
if (number == 0)
|
||||||
{
|
{
|
||||||
return "Không";
|
return "không";
|
||||||
}
|
}
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
if (number < 0)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
number = -number;
|
number = -number;
|
||||||
prefix = "Âm ";
|
prefix = "âm ";
|
||||||
}
|
}
|
||||||
String soFar = "";
|
String soFar = "";
|
||||||
|
|
||||||
|
|
@ -277,26 +271,68 @@ public class AmtInWords_VI implements AmtInWords
|
||||||
if (amount == null)
|
if (amount == null)
|
||||||
return amount;
|
return amount;
|
||||||
//
|
//
|
||||||
|
int numberOfCommas = 0;
|
||||||
|
int numberOfPeriods = 0;
|
||||||
StringBuffer sb = new StringBuffer ();
|
StringBuffer sb = new StringBuffer ();
|
||||||
int pos = amount.lastIndexOf ('.');
|
int period = amount.lastIndexOf ('.');
|
||||||
int pos2 = amount.lastIndexOf (',');
|
numberOfPeriods = amount.replaceAll("[^\\.]","").length();
|
||||||
if (pos2 > pos)
|
int comma = amount.lastIndexOf (',');
|
||||||
pos = pos2;
|
numberOfCommas = amount.replaceAll("[^,]","").length();
|
||||||
String oldamt = amount;
|
int newpos = 0;
|
||||||
amount = amount.replaceAll (",", "");
|
String decamt ="";
|
||||||
int newpos = amount.lastIndexOf ('.');
|
if (comma > period) //like 1.000.000,89 or 1,000,000 or 120,355 (a hundred and twenty 355/1000)
|
||||||
long dollars = Long.parseLong(amount.substring (0, newpos));
|
|
||||||
sb.append (convert (dollars));
|
|
||||||
for (int i = 0; i < oldamt.length (); i++)
|
|
||||||
{
|
{
|
||||||
if (pos == i) // we are done
|
if (period != -1) //like 1.000.000,89
|
||||||
{
|
{
|
||||||
String cents = oldamt.substring (i + 1);
|
decamt = amount.substring(comma+1,amount.length());
|
||||||
sb.append (' ').append (cents).append ("/100");
|
amount = amount.replaceAll ("\\.", "");
|
||||||
break;
|
newpos = amount.lastIndexOf (',')+1;
|
||||||
|
}
|
||||||
|
else if ((amount.length()-comma-1) <=2 )
|
||||||
|
{
|
||||||
|
decamt = amount.substring(comma+1,amount.length());
|
||||||
|
newpos = comma+1;
|
||||||
|
}
|
||||||
|
else //like 1,000,000
|
||||||
|
{ decamt = "";
|
||||||
|
amount = amount.replaceAll (",", "");
|
||||||
|
newpos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (comma < period) //like 1,000.09 or 1.000.000 or 120.355 (a hundred and twenty 355/100)
|
||||||
|
{
|
||||||
|
if ((comma !=-1) | (numberOfPeriods ==1))//like 1,000.09
|
||||||
|
{
|
||||||
|
decamt = amount.substring(period+1,amount.length());
|
||||||
|
amount = amount.replaceAll (",", "");
|
||||||
|
newpos = amount.lastIndexOf ('.')+1;
|
||||||
|
}
|
||||||
|
else //like 1.000.000
|
||||||
|
{
|
||||||
|
decamt = "";
|
||||||
|
amount = amount.replaceAll ("\\.", "");
|
||||||
|
newpos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString ();
|
else if ((comma==-1) && (period ==-1)) //like 1000000
|
||||||
|
{
|
||||||
|
decamt = "";
|
||||||
|
newpos = 0;
|
||||||
|
}
|
||||||
|
long dollars = 0;
|
||||||
|
long decima = 0;
|
||||||
|
if (newpos !=0)
|
||||||
|
{ dollars = Long.parseLong(amount.substring (0, newpos-1));
|
||||||
|
sb.append (convert (dollars));
|
||||||
|
decima = Long.parseLong(decamt);
|
||||||
|
sb.append(" phẩy ").append(convert(decima));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dollars = Long.parseLong(amount.substring(0,amount.length()));
|
||||||
|
sb.append (convert(dollars));
|
||||||
|
}
|
||||||
|
return sb.toString ().replaceAll(" ", " ").replaceAll("linh nghìn", "nghìn").replaceAll("linh triệu","triệu").replaceAll("linh tỉ","tỉ");
|
||||||
} // getAmtInWords
|
} // getAmtInWords
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -325,18 +361,25 @@ public class AmtInWords_VI implements AmtInWords
|
||||||
// aiw.print (".23"); Error
|
// aiw.print (".23"); Error
|
||||||
aiw.print ("0.23");
|
aiw.print ("0.23");
|
||||||
aiw.print ("1.23");
|
aiw.print ("1.23");
|
||||||
aiw.print ("12.345");
|
aiw.print ("12,345");
|
||||||
aiw.print ("103.45");
|
aiw.print ("103.45");
|
||||||
aiw.print ("114.45");
|
aiw.print ("114,45");
|
||||||
aiw.print ("123.45");
|
aiw.print ("123.45");
|
||||||
aiw.print ("1023.45");
|
aiw.print ("500000000");
|
||||||
aiw.print ("1234.56");
|
aiw.print ("1234.56");
|
||||||
aiw.print ("12345.78");
|
aiw.print ("12345.78");
|
||||||
aiw.print ("103457.89");
|
aiw.print ("100457.89");
|
||||||
aiw.print ("1,234,578.90");
|
aiw.print ("100,234,578.90");
|
||||||
aiw.print ("1,034,578.90");
|
aiw.print ("12,034,578.90");
|
||||||
aiw.print ("1,004,008.90");
|
aiw.print ("103,004,008.90");
|
||||||
aiw.print ("1,201,034,578.90");
|
aiw.print ("1,201,034,578.90");
|
||||||
|
aiw.print ("12,201,034,578.90");
|
||||||
|
aiw.print ("10220134578");
|
||||||
|
aiw.print ("1.093.201.034.578");
|
||||||
|
aiw.print ("100,932,010,345,780");
|
||||||
|
aiw.print ("109.320.103,48");
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
} // AmtInWords_VI
|
} // AmtInWords_VI
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue