[GLLUG] Changing words into numbers
john at technolalia.org
Tue Aug 14 09:46:23 UTC 2018
A problem which I think has a philosophical side as much as a practical one:
What is the best way (or what are the ways) to replace numbers written
out in words with digits?
(e.g. "the year one thousand eight hundred and seventy six" to 1776, or
"nine hundred and ninety pounds" to 999 pounds).
One obvious solution I've thought of is to automatically generate a list
of all numbers spelled out from one to n, pair them with the numerical
value, then simply loop through the list and target texts substituting
the former with the latter. But this strikes me as very blunt and very
uneconomical. And probably impracical in that the top most number may be
very high (I don't know what the highest number in the texts I have is,
though I have seen 'thirty-eight million nine hundred and ninety-seven').
Could there be a regex solution that generates the number from the words?
What other approaches could I take?
Thanks in advance,
More information about the GLLUG