Converting Numbers to Words

Converting Numbers to Words


Sometimes it is very much required in coding to convert numbers to words and print them as can be seen in Railway reservation tickets. Explained in "Converting Numbers to Words" with Java syntax.

Following program illustrates "Converting Numbers to Words".

Converting Numbers to Words

The integer number is taken from keyboard, converted and printed in words. The number can be taken from a file or database or GUI also. Here, java.util.Scanner class is used to take keyboard input. Other styles of keyboard input are using the classes DataInputStream and BufferedReader.

Code is self-explanatory, involves small logic of separating each digit in the integer number, converting each digit to an array of words, exchanging the word and printing each word.

Precaution: Write as if(n<=0) All ARRAY Operations at a Glance

Constructor related Topics

32 thoughts on “Converting Numbers to Words

  1. Raj Kumar

    Sir How to print nos greater than crore i.e for input like below
    Please enter the number to convert it to Roman.
    5674389097
    java.util.InputMismatchException: For input string: “5674389097”
    at java.util.Scanner.nextInt(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at javaBasics.NumberToRoman.convertNumberToRoman(NumberToRoman.java:25)
    at javaBasics.NumberToRoman.main(NumberToRoman.java:12)

  2. poornima

    i need a conversion from decimal to word like 999999999.99 to ninety nine crores ninety nine lacks ninety nine thousands nine hundred and ninety nine point nine nine

        1. Madhava Nandan Rao

          25/10=2;
          25%10=5;

          System.out.println(ten[25/10]+” “+one[25%10]);

          Replace the above values… here ten, one are array names. Observe them.

  3. Jeevan

    Sir,
    When I give the input numbers greater than 9999, the program “Converting Numbers to Words” in your site giving an exception.

    Can I know the reason why it is so?

    Thanks & regards
    Jeevan.

Leave a Reply

Your email address will not be published. Required fields are marked *