Simplified AmtInWords_BG and fixed a problem with separator other than comma or with no separator.
This commit is contained in:
parent
a205b9e9b4
commit
2d57b2e869
|
@ -19,6 +19,7 @@ package org.compiere.util;
|
||||||
*
|
*
|
||||||
*@author Kostadin Mitev -The class is based on the AmtInWords_EN.java written by jjanke
|
*@author Kostadin Mitev -The class is based on the AmtInWords_EN.java written by jjanke
|
||||||
*@version $Id: AmtInWords_BG.java,v 0.1 2007/12/21 $
|
*@version $Id: AmtInWords_BG.java,v 0.1 2007/12/21 $
|
||||||
|
*@version $Id: v, 0.2 2008/06/10 -Simplified. Changed to work with both a dot and a full stop as a separator and without a separator.
|
||||||
*/
|
*/
|
||||||
public class AmtInWords_BG implements AmtInWords
|
public class AmtInWords_BG implements AmtInWords
|
||||||
{
|
{
|
||||||
|
@ -177,25 +178,21 @@ public class AmtInWords_BG implements AmtInWords
|
||||||
{
|
{
|
||||||
if (amount == null)
|
if (amount == null)
|
||||||
return amount;
|
return amount;
|
||||||
//
|
|
||||||
StringBuffer sb = new StringBuffer ();
|
StringBuffer sb = new StringBuffer ();
|
||||||
int pos = amount.lastIndexOf (',');
|
|
||||||
String oldamt = amount;
|
|
||||||
amount = amount.replaceAll (" ", "").replaceAll("\u00A0", "");
|
amount = amount.replaceAll (" ", "").replaceAll("\u00A0", "");
|
||||||
int newpos = amount.lastIndexOf (',');
|
char sep = amount.contains(",")?',':'.'; //Try to determine the separator either comma or a full stop
|
||||||
long levs = Long.parseLong(amount.substring (0, newpos));
|
int pos = amount.lastIndexOf (sep);
|
||||||
sb.append (convert (levs));
|
long levs = Long.parseLong((pos >=0)?amount.substring (0, pos):amount);
|
||||||
for (int i = 0; i < oldamt.length (); i++)
|
sb.append (convert (levs) + " " + lev[levs ==1?0:1]);
|
||||||
{
|
if(pos > 0) {
|
||||||
if (pos == i) //we are done
|
String stotinki = amount.substring (pos + 1);
|
||||||
{
|
if(stotinki.length() > 2){
|
||||||
String stotinki = oldamt.substring (i + 1);
|
stotinki = stotinki.substring(0,2);
|
||||||
if(stotinki.length() > 2){
|
}
|
||||||
stotinki = stotinki.substring(0,2);
|
sb.append (" " + concat + " ")
|
||||||
}
|
.append (convert(Long.parseLong(stotinki)))
|
||||||
sb.append (" " + lev[levs ==1?0:1] + " " + concat + " ").append (convert(Long.parseLong(stotinki))).append (" \u0441\u0442\u043E\u0442\u0438\u043D\u043A\u0438"); // "lw i cents stotinki"
|
.append (" \u0441\u0442\u043E\u0442\u0438\u043D\u043A\u0438"); //stotinki"
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sb.toString ();
|
return sb.toString ();
|
||||||
} //getAmtInWords
|
} //getAmtInWords
|
||||||
|
@ -223,6 +220,8 @@ public class AmtInWords_BG implements AmtInWords
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
AmtInWords_BG aiw = new AmtInWords_BG();
|
AmtInWords_BG aiw = new AmtInWords_BG();
|
||||||
|
aiw.print("0.23");
|
||||||
|
aiw.print("23");
|
||||||
aiw.print ("0,23");
|
aiw.print ("0,23");
|
||||||
aiw.print ("1,23");
|
aiw.print ("1,23");
|
||||||
aiw.print ("12,345");
|
aiw.print ("12,345");
|
||||||
|
|
Loading…
Reference in New Issue