javanumberscpu-wordthai

How to convert numeric to Thai language word in Java?


I used the following code but it does not work:

    import java.text.NumberFormat;
    import java.util.Locale;
    
        public class NumToword {
           public static void main(String str[]){
                String outputString = new String();
               Locale[] thaiLocale = {
                            new Locale("th"),
                            new Locale("th", "TH"),
                            new Locale("th", "TH", "TH")
                        };
               for (Locale locale : thaiLocale) {
                   NumberFormat nf = NumberFormat.getNumberInstance(locale);
                   outputString = outputString + locale.toString() + ": ";
                    outputString = outputString + nf.format(573.34) + "\n";
                    System.out.println("word : "+outputString);
               }
           }
       }

Solution

  • I think you want the System.out.println("word : "+outputString); outside of the for loop and to make it identical to: http://docs.oracle.com/javase/tutorial/i18n/locale/create.html remove the "word : ". IE:

    import java.text.NumberFormat;
    import java.util.Locale;
    
    public class NumToword {
       public static void main(String str[]){
            String outputString = new String();
           Locale[] thaiLocale = {
                        new Locale("th"),
                        new Locale("th", "TH"),
                        new Locale("th", "TH", "TH")
                    };
           for (Locale locale : thaiLocale) {
               NumberFormat nf = NumberFormat.getNumberInstance(locale);
               outputString = outputString + locale.toString() + ": ";
                outputString = outputString + nf.format(573.34) + "\n";
           }
           System.out.println(outputString);
       }
      }