Java Program to Convert Numbers to Words

This post shows how you can write a Java program to convert numbers to words.
For example– If you enter number 123 output should be One hundred twenty three in words .
In the post conversion of number to words is done for both international system and Indian system.

Java program for converting number to words – International system

If you observe in international system comma is placed after every three digits.

223,544,578 – Two hundred twenty three million five hundred forty four thousand five hundred seventy eight.

Three digits placed in between each comma are worded in the same way, as shown in the above example 223- Two hundred twenty three, 544- five hundred forty four. You just need to put the correct denomination in between the three digits.

This observation forms the logic for the Java program to convert number to words. Starting from right take 3 digits at a time and convert them to word and place the correct denomination in progression.

Output

Note that this program works till billion, if you want to go further then add it in “hundreds” array. You will also require to change the type from int to double.

Java program for converting number to words – Indian system

If you observe in Indian system comma is placed after every two digits, barring the first instance where it is placed after three digits.

22,35,44,578 – Twenty two crore thirty five lakh forty four thousand five hundred and seventy eight only

In Indian system, starting from right you need to take 3 digits first time and then move by 2 digits in every iteration.

Output

That’s all for the topic Java Program to Convert Numbers to Words. If something is missing or you have something to share about the topic please write a comment.


You may also like

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.