Home » Java Program Number to Word

Java Program Number to Word

by Online Tutorials Library

Java Program Number to Word

In this section, we will create a Java program that converts the given number into words. For example, if the given number is 54,297 then the output should be Fifty-Four Thousand Two Hundred Ninety-Seven. Let’s create a Java program for the same.

NumberToWordExample1.java

Output:

Java Program Number to Word

The number is not limited to four digits. Then what if the user enters more than 5 five digits numbers. The above program does not work for large digit numbers.

Converting Large Numbers into Words

The logic for converting the large digit numbers is quite different. Let’s see the approach to convert large digits numbers.

NumberToWordExample2.java

Output:

Java Program Number to Word

Converting Very Long Numbers into Words

The logic for the conversion of very long numbers into words is different from the previous one. Before moving ahead, it is important to learn the name of large numbers. The following table describes the name of the larger numbers.

Name Short Scale
(US, English Canada, modern British, Australia, and Eastern Europe)
Long Scale
(French Canada, older British, Western & Central Europe)
Million 106 106
Milliard Not used 109
Billion 109 1012
Billiard Not used 1015
Trillion 1012 1018
Quadrillion 1015 1024
Quintillion 1018 1030
Sextillion 1021 1036
Septillion 1024 1042
Octillion 1027 1048
Nonillion 1030 1054
Decillion 1033 1060
Undecillion 1036 1066
Duodecillion 1039 1072
Tredecillion 1042 1078
Quattuordecillion 1045 1084
Quindecillion 1048 1090
Sexdecillion 1051 1096
Septendecillion 1054 10102
Octodecillion 1057 10108
Novemdecillion 1060 10114
Vigintillion 1063 10120
Centillion 10303 10600

Let’s create a Java program that converts very long numbers into words.

The following Java program also converts the negative and decimal numbers into words.

NumberToWordExample3.java

Output:

0 = zero  4 = four  10 = ten  12 = twelve  100 = one hundred  108 = one hundred eight  299 = two hundred ninety-nine  1000 = one thousand  1003 = one thousand three  2040 = two thousand forty  45213 = forty-five thousand two hundred thirteen  100000 = one hundred thousand  100005 = one hundred thousand five  100010 = one hundred thousand ten  202020 = two hundred two thousand twenty  202022 = two hundred two thousand twenty-two  999999 = nine hundred ninety-nine thousand nine hundred ninety-nine  1000000 = one million  1000001 = one million one  10000000 = ten million  10000007 = ten million seven  99999999 = ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine  9223372036854775807 = nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred seven  -9223372036854775808 = minus nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred eight  0001.2 = one and two tenth  3.141592 = three and one hundred forty-one thousand five hundred ninety-two millionth  

Even, we can convert 100 digits long number with the help of the above program.


You may also like