-
Notifications
You must be signed in to change notification settings - Fork 20.8k
Description
What would you like to Propose?
A Java-based utility for converting English word representations of numbers into their numeric form. This feature will handle various cases, including whole numbers, negative numbers, decimals, large values, and invalid inputs.
Issue details
The WordsToNumber utility should accurately convert word-based numerical expressions into BigDecimal, supporting proper handling of scaling, negative values, and edge cases.
Test cases:
String[] testCases = {
"zero", // 0
"five", // 5
"twenty one", // 21
"one hundred one", // 101
"three hundred and forty two", // 342
"one million", // 1000000
"one billion", // 1000000000
"negative five", // -5
"negative one hundred and twenty", // -120
"three point one four one five", // 3.1415
"negative two point seven one eight", // -2.718
"zero point zero zero zero zero zero zero one", // 1E-7
"one billion point zero zero zero zero zero zero zero zero zero one", // 1000000000.000000001
"negative nine trillion eight hundred seventy six billion five hundred forty three million two hundred ten thousand nine hundred eighty seven", // -9876543210987
"twent four", // Invalid: unknown word
"twenty thirteen", // Invalid: unexpected word
"one hundred hundred", // Invalid: unexpected word
"negative negative ten" // Invalid: multiple negatives
};
Additional Information
Why Is This Needed?
The repository contains many numerical conversion utilities, but a Words to Number conversion feature is missing.
Useful for applications requiring text-based number processing, natural language interfaces, and financial applications.
Ensures robust validation and consistency.