Skip to content

Instantly share code, notes, and snippets.

@rawsh
Created December 26, 2016 19:30
Show Gist options
  • Save rawsh/35a77d5238bd5a2974110ba4618d8be5 to your computer and use it in GitHub Desktop.
Save rawsh/35a77d5238bd5a2974110ba4618d8be5 to your computer and use it in GitHub Desktop.
Code
int ones = t % 10;
int twos = (t-t%10)/10;
String[] singledigits = new String[] {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
String[] doubledigits = new String[] {"", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
String[] teens = new String[] {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
if (twos == 0) {
inwords = singledigits[ones];
} else if (twos == 1) {
inwords = teens[ones];
} else {
if (ones != 0) {
inwords = doubledigits[twos] + " " + singledigits[ones];
} else {
inwords = doubledigits[twos];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment