package com.ffii.core.utils;

public class NumberUtils extends org.apache.commons.lang3.math.NumberUtils{

    private static final String[] units = { "", "one", "two", "three", "four",
            "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
            "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
            "eighteen", "nineteen" };

    private static final String[] tens = { 
            "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
            "eighty", "ninety" };

    public static String convertToWord(int number) {
        if (number == 0) {
            return "zero";
        }

        if (number < 0) {
            return "minus " + convertToWord(-number);
        }

        if (number < 20) {
            return units[number];
        }

        if (number < 100) {
            return tens[number / 10] + ((number % 10 != 0) ? " " : "") + units[number % 10];
        }

        if (number < 1000) {
            return units[number / 100] + " hundred" + ((number % 100 != 0) ? " " : "") + convertToWord(number % 100);
        }

        if (number < 1000000) {
            return convertToWord(number / 1000) + " thousand" + ((number % 1000 != 0) ? " " : "") + convertToWord(number % 1000);
        }

        if (number < 1000000000) {
            return convertToWord(number / 1000000) + " million" + ((number % 1000000 != 0) ? " " : "") + convertToWord(number % 1000000);
        }

        return convertToWord(number / 1000000000) + " billion" + ((number % 1000000000 != 0) ? " " : "") + convertToWord(number % 1000000000);
    }
}
