tags:

views:

168

answers:

1

Hi all

I heard that we can use the English words to express the number. Like using One hundred to express 100. Does anyone know which function can do it?

Best Regards,

+2  A: 

I see that Wolfram Alpha can do that, so here's a kludgy little function that sends the English string to Wolfram Alpha and parses the result:

w2n[s_String] := ToExpression[StringCases[
  Import["http://www.wolframalpha.com/input/?i=" <> StringReplace[s, " "->"+"],
        "String"], 
  RegularExpression["Hold\\[([^\\]]*)\\]"] -> "$1"][[1]]]

Example:

w2n["two million six hundred sixty-six"]

> 2000666

Does Wolfram Alpha provide an actual API? That would be really great!

PS: They have one now but it's expensive: http://products.wolframalpha.com/api/

PPS: I notice that the wolframalpha results page changed a bit and my scraping no longer works. Some variant on that regular expression should work though.

dreeves
I should probably do an actual url_encode instead of just replacing spaces with pluses, but for numbers in English that seems to suffice.
dreeves