File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
src/main/java/com/thealgorithms/conversions Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 3
3
import java .math .BigDecimal ;
4
4
import java .util .*;
5
5
6
+ /**
7
+ A Java-based utility for converting English word representations of numbers
8
+ into their numeric form. This utility supports whole numbers, decimals,
9
+ large values up to trillions, and even scientific notation where applicable.
10
+ It ensures accurate parsing while handling edge cases like negative numbers,
11
+ improper word placements, and ambiguous inputs.
12
+ *
13
+ */
14
+
6
15
public final class WordsToNumber {
7
16
private WordsToNumber () {
8
17
}
@@ -97,13 +106,13 @@ public static String convert(String numberInWords) {
97
106
98
107
Integer number = NUMBER_MAP .getOrDefault (word , null );
99
108
if (number != null ) {
100
- if (number == 0 && !(currentChunkIsZero && chunks .isEmpty ())) return "Invalid Input. Unexpected word : " + word ;
109
+ if (number == 0 && !(currentChunkIsZero && chunks .isEmpty ())) return "Invalid Input. Unexpected Word : " + word ;
101
110
BigDecimal bigDecimalNumber = BigDecimal .valueOf (number );
102
111
103
112
if (currentChunkIsZero || isAdditionSafe (currentChunk , bigDecimalNumber ))
104
113
currentChunk = currentChunk .add (bigDecimalNumber );
105
114
else
106
- return "Invalid Input. Unexpected word : " + word ;
115
+ return "Invalid Input. Unexpected Word : " + word ;
107
116
continue ;
108
117
}
109
118
You can’t perform that action at this time.
0 commit comments