1
package org.apache.lucene.util;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
23
public final class English {
25
private English() {} // no instance
27
public static String longToEnglish(long i) {
28
StringBuilder result = new StringBuilder();
29
longToEnglish(i, result);
30
return result.toString();
33
public static void longToEnglish(long i, StringBuilder result) {
35
result.append("zero");
39
result.append("minus ");
42
if (i >= 1000000000000000000l) { // quadrillion
43
longToEnglish(i / 1000000000000000000l, result);
44
result.append("quintillion, ");
45
i = i % 1000000000000000000l;
47
if (i >= 1000000000000000l) { // quadrillion
48
longToEnglish(i / 1000000000000000l, result);
49
result.append("quadrillion, ");
50
i = i % 1000000000000000l;
52
if (i >= 1000000000000l) { // trillions
53
longToEnglish(i / 1000000000000l, result);
54
result.append("trillion, ");
55
i = i % 1000000000000l;
57
if (i >= 1000000000) { // billions
58
longToEnglish(i / 1000000000, result);
59
result.append("billion, ");
62
if (i >= 1000000) { // millions
63
longToEnglish(i / 1000000, result);
64
result.append("million, ");
67
if (i >= 1000) { // thousands
68
longToEnglish(i / 1000, result);
69
result.append("thousand, ");
72
if (i >= 100) { // hundreds
73
longToEnglish(i / 100, result);
74
result.append("hundred ");
77
//we know we are smaller here so we can cast
79
switch (((int) i) / 10) {
81
result.append("ninety");
84
result.append("eighty");
87
result.append("seventy");
90
result.append("sixty");
93
result.append("fifty");
96
result.append("forty");
99
result.append("thirty");
102
result.append("twenty");
113
result.append("nineteen ");
116
result.append("eighteen ");
119
result.append("seventeen ");
122
result.append("sixteen ");
125
result.append("fifteen ");
128
result.append("fourteen ");
131
result.append("thirteen ");
134
result.append("twelve ");
137
result.append("eleven ");
140
result.append("ten ");
143
result.append("nine ");
146
result.append("eight ");
149
result.append("seven ");
152
result.append("six ");
155
result.append("five ");
158
result.append("four ");
161
result.append("three ");
164
result.append("two ");
167
result.append("one ");
176
public static String intToEnglish(int i) {
177
StringBuilder result = new StringBuilder();
178
longToEnglish(i, result);
179
return result.toString();
182
public static void intToEnglish(int i, StringBuilder result) {
183
longToEnglish(i, result);
186
public static void main(String[] args) {
187
System.out.println(longToEnglish(Long.parseLong(args[0])));