1package com.osroyale.util;
32* This
class specially written to convert the given number into words. It will
33 * support upto 1 crore.
35 * @author SANTHOSH REDDY MANDADI
36 * @version release: 2_0_48
37 * @since April 03 2008
46 private Words(
long num) {
50 public void setNumber(
long num) {
54 public long getNumber() {
58 public static Words getInstance(
long num) {
59 return new Words(num);
62 public static String leftChars(String str,
int n) {
63 if (str.length() <= n)
66 return str.substring(0, n);
69 public static String rightChars(String str,
int n) {
70 if (str.length() <= n)
73 return str.substring(str.length() - n);
76 public long leftChars(
int n) {
77 return Long.parseLong(leftChars(Long.toString(num), n));
80 public long rightChars(
int n) {
81 return Long.parseLong(rightChars(Long.toString(num), n));
84 public long leftChars(
long num,
int n) {
85 return Long.parseLong(leftChars(Long.toString(num), n));
88 public long rightChars(
long num,
int n) {
89 return Long.parseLong(rightChars(Long.toString(num), n));
92 public int length(
long num) {
93 return Long.toString(num).length();
96 private String belowTen(
long x) {
120 private String belowTwenty(
long x) {
148 private String belowHundred(
long x) {
152 return belowTwenty(x);
153 switch ((
int) leftChars(x, 1)) {
155 return "Twenty " + belowTen(rightChars(x, 1));
157 return "Thirty " + belowTen(rightChars(x, 1));
159 return "Fourty " + belowTen(rightChars(x, 1));
161 return "Fifty " + belowTen(rightChars(x, 1));
163 return "Sixty " + belowTen(rightChars(x, 1));
165 return "Seventy " + belowTen(rightChars(x, 1));
167 return "Eighty " + belowTen(rightChars(x, 1));
169 return "Ninety " + belowTen(rightChars(x, 1));
174 private String belowThousand(
long x) {
178 return belowTwenty(x);
180 return belowHundred(x);
181 return belowTen(leftChars(x, 1)) +
"Hundred " + belowHundred(rightChars(x, 2));
184 private String belowLakh(
long x) {
188 return belowTwenty(x);
190 return belowHundred(x);
192 return belowThousand(x);
194 return belowTen(leftChars(x, 1)) +
"Thousand " + belowThousand(rightChars(x, 3));
196 return belowHundred(leftChars(x, 2)) +
"Thousand " + belowThousand(rightChars(x, 3));
199 public String belowCrore(
long x) {
203 return belowTwenty(x);
205 return belowHundred(x);
207 return belowThousand(x);
211 return belowTen(leftChars(x, 1)) +
"Lakh " + belowLakh(rightChars(x, 5));
213 return belowHundred(leftChars(x, 2)) +
"Lakh " + belowLakh(rightChars(x, 5));
216 public String belowBillion(
long x) {
220 return belowTwenty(x);
222 return belowHundred(x);
224 return belowThousand(x);
227 else if (x < 100000000)
228 return belowCrore(x);
231 return belowTen(leftChars(x, 1)) +
"Bilion " + belowCrore(rightChars(x, 7));
233 return belowHundred(leftChars(x, 2)) +
"Bilion " + belowCrore(rightChars(x, 7));
236 public String getNumberInWords() {
238 return belowTen(num);
240 return belowTwenty(num);
242 return belowHundred(num);
244 return belowThousand(num);
245 else if (num < 100000)
246 return belowLakh(num);
247 else if (num < 10000000)
248 return belowCrore(num);
249 else if (num < 1000000000)
250 return belowBillion(num);