As far as I know, there is no library for this, but you can think like this:
create three types of tokens
a. one, two, three .................... nine
b. eleven - nineteen, twenty, thirty, ............ ninety
c. one hundred, one thousand, ........ and larger values
Now analyze your input line and match it with your tokens. Just for a basic idea, you can think like this:
Step 1. Create Tokens from the Token Token
step 2. corresponds to the rightmost line and matches tokens
Step 3. Match one line to the right and match with tokens and calculate
e.g. ONE THOUSAND FIVE HUNDRED FIFTY THREE
let sum = 0
first line = Thus, the sum + = 3
second line = FiFTY, therefore sum + = 50;
third line = One Hundred, so you need to multiply the fourth line by 100 and add so sum + = f * 100 .. etc.
This is just a basic idea. That way you can implement it perfectly after planning it right
stinepike
source share