How to read values from numbers written as words?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Reading and converting numbers that are written as words can be a challenging task, especially when dealing with different linguistic rules and varying formats. This article provides a comprehensive guide on understanding and converting these word-based numbers into their respective numeric forms.
Understanding the Basics
To effectively read numbers from words, it's crucial to understand the fundamental components that constitute numeric words. These include units, tens, hundreds, and so on.
Components:
- Units (0-9): The simplest form of numbers, represented as:
- Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine
- Tens (10-90): Represent numbers such as:
- Ten, Twenty, Thirty, Forty, Fifty, Sixty, Seventy, Eighty, Ninety
- Teens (11-19): Special cases that combine units with ten:
- Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, Seventeen, Eighteen, Nineteen
- Larger Units: These include hundreds, thousands, millions, etc.
Technical Pattern Recognition
To break down numbers written as words into recognizable patterns, it's useful to consider each component's place value, as well as the link words like "and" used in some conventions.
- Hundreds and Thousands:
- e.g., "Two hundred and thirty-four" =>
200 + 30 + 4
- Complex Numbers:
- Combining different components with connectors:
- e.g., "Five thousand two hundred and eleven" =>
5000 + 200 + 11
Conversion Process
Step-by-Step Methodology
- Identify and Parse the Word Form:
- Break down the string of words into recognizable number blocks.
- Mapping Words to Numeric Values:
- Create a dictionary where each word corresponds to its numeric value. For example:
- Decide the stepping through the components to either add or multiply:
- e.g., "Three hundred" means
3 * 100.
- Sum up the values from step 3 to get the final number.
- Compound forms like "twenty-one" might require specific handling to map appropriately.
- Ensure proper handling of special cases such as "a hundred" vs "one hundred."
- Be aware of different terminologies in other dialects of English.

