Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Numbers to Words #99

Open
curran opened this issue Jul 10, 2020 · 3 comments
Open

Convert Numbers to Words #99

curran opened this issue Jul 10, 2020 · 3 comments

Comments

@curran
Copy link

curran commented Jul 10, 2020

Perhaps out of scope, but an interesting challenge: convert numbers to words.

Inspired by the StackOverflow: Indian Numbering System. How to Convert into the Official and Common-Use Numbering Systems Words/Strings.

@curran
Copy link
Author

curran commented Jul 10, 2020

For example, English locale:

test.equal(f(0), "zero");
test.equal(f(1), "one");
test.equal(f(2), "two");
test.equal(f(3), "three");
test.equal(f(4), "four");
test.equal(f(5), "five");
test.equal(f(6), "six");
test.equal(f(7), "seven");
test.equal(f(8), "eight");
test.equal(f(9), "nine");
test.equal(f(10), "ten");
test.equal(f(11), "eleven");
...
test.equal(f(99), "ninety nine");
test.equal(f(100), "one hundred");
test.equal(f(101), "one hundred and one");
test.equal(f(123), "one hundred and twenty three");
test.equal(f(1000), "one thousand");
test.equal(f(1101), "one thousand one hundred and one");
test.equal(f(10000), "ten thousand");
test.equal(f(100000), "one hundred thousand");
test.equal(f(1000000), "one million");
test.equal(f(10000000), "one billion");
test.equal(f(100000000), "one trillion");

@curran
Copy link
Author

curran commented Jul 10, 2020

For example, Indian locale (from StackOverflow: Indian Numbering System. How to Convert into the Official and Common-Use Numbering Systems Words/Strings):

test.equal(f(50), "fifty");
test.equal(f(12000), "twelve thousand");
test.equal(f(777000), "seven lakh seventy seven thousand");
test.equal(f(550001), "five lakh fifty thousand one");
test.equal(f(12345678) "one crore twenty three lakh forty five thousand six hundred seventy eight");
test.equal(f(123456789) "twelve crore thirty four lakh fifty six thousand seven hundred eighty nine");
test.equal(f(1234567890) "one hundred twenty three crore forty five lakh sixty seven thousand eight hundred ninety");
test.equal(f(12345678900) "one thousand two hundred thirty four crore fifty six lakh seventy eight thousand nine hundred");

Note: I've modified the original test cases by:

  • making everything lower case,
  • removing commas, and
  • removing dashes between numbers.

I'm not sure if those are standard practices in India (they might be), but they seemed off to me. Input welcome!

@MohsenAlyafei
Copy link

Very interesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants