Convert word to number

studio

#1

Hi,

I have some word that i want to convert to number
By exemple : One thousand four hundred and four -> 1484

I would like to use Humanizer method with Humanizer namespace but it doesn’t work.
Any idea ?


#2

Hi,

This is probably just a workaround, but you could store the words into a table or list.
ONE,1
TWO,2
THREE,3
FOUR,4
.
.
HUNDRED,00
THOUSAND,000
AND,

Then, you can access the value for each word using .Select

ForEach word In text.Split(" "c)
Assign strNumber = strNumber+dt.Select("[value] = "+UCase(word))(0).Item(1).ToString

You would also need to figure a way to replace the zeros, sorry.
Not the most ideal but will work.

Thanks.


#3

This might not be the most efficient one but I am sure the result is always correct here.
Google the word with "Plus zero"
Example: "Twenty thousand plus zero"
Google will always return a calculator from which the number can be found.
Google Result for 2100

Attached is a sample workflow:
Word to number.xaml (8.8 KB)


#4

how to covert Number to Word


#5

Just do the same as the other one but use
225 in english in Google search and capture the result
https://www.google.co.in/search?rlz=1C1CHBF_enIN757IN757&q=225+in+english&oq=225+in+english


#6

Assign Dict= Dictionary<string,long>
{{“zero”,0},{“one”,1},{“two”,2},{“three”,3},{“four”,4},
{“five”,5},{“six”,6},{“seven”,7},{“eight”,8},{“nine”,9},
{“ten”,10},{“eleven”,11},{“twelve”,12},{“thirteen”,13},
{“fourteen”,14},{“fifteen”,15},{“sixteen”,16},
{“seventeen”,17},{“eighteen”,18},{“nineteen”,19},{“twenty”,20},
{“thirty”,30},{“forty”,40},{“fifty”,50},{“sixty”,60},
{“seventy”,70},{“eighty”,80},{“ninety”,90},{“hundred”,100},
{“thousand”,1000},{“million”,1000000},{“billion”,1000000000},
{“trillion”,1000000000000},{“quadrillion”,1000000000000000},
{“quintillion”,1000000000000000000}};

Assign no = Regex.Matches(inputno, @"\w+").Cast()
.Select(m => m.Value.ToLowerInvariant())
.Where(v => Dict.ContainsKey(v))
.Select(v => Dict(v])
assign acc = 0
total = 0
foreach(n in no)

    if(n >= 1000)
    
        total += (acc * n)
        acc = 0
    
    else

if(n >= 100)
acc *= n

    else acc += n

Assign output=(total + acc)  * ( no.StartsWith("minus",
      StringComparison.InvariantCultureIgnoreCase) ? -1 : 1);

#7

Thanks Bikash