Helper function for converting numbers to words. There is same function available in PHPs NumberFormatter class, but using it is not always possible, since it's not enabled by default.
Source code viewer
/** * Helper function for converting numbers to words. * * @param int $num * Integer that is going to be converted to words. * * @return string * Return the number in words. */ function NumberToWord($num) { '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', ); '', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred', ); '', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion', ); $levels = (int) (($num_length + 2) / 3); $max_length = $levels * 3; $levels--; $hundreds = (int) ($num_levels[$i] / 100); $hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' hundred' . ' ' : ''); $tens = (int) ($num_levels[$i] % 100); $singles = ''; if ($tens < 20) { $tens = ($tens ? ' ' . $list1[$tens] . ' ' : ''); } else { $tens = (int) ($tens / 10); $tens = ' ' . $list2[$tens] . ' '; $singles = (int) ($num_levels[$i] % 10); $singles = ' ' . $list1[$singles] . ' '; } $words[] = $hundreds . $tens . $singles . (($levels && (int) $num_levels[$i]) ? ' ' . $list3[$levels] . ' ' : ''); } }Programming Language: PHP