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 33import java .math .BigDecimal ;
44import java .util .*;
55
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+
615public final class WordsToNumber {
716 private WordsToNumber () {
817 }
@@ -97,13 +106,13 @@ public static String convert(String numberInWords) {
97106
98107 Integer number = NUMBER_MAP .getOrDefault (word , null );
99108 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 ;
101110 BigDecimal bigDecimalNumber = BigDecimal .valueOf (number );
102111
103112 if (currentChunkIsZero || isAdditionSafe (currentChunk , bigDecimalNumber ))
104113 currentChunk = currentChunk .add (bigDecimalNumber );
105114 else
106- return "Invalid Input. Unexpected word : " + word ;
115+ return "Invalid Input. Unexpected Word : " + word ;
107116 continue ;
108117 }
109118
You can’t perform that action at this time.
0 commit comments