Program to convert a given number to words | Set 2 | strings at index 0 is not used , it is to make array indexing simple ; strings at index 0 and 1 are not used , they is to make array indexing simple ; n is 1 - or 2 - digit number ; if n is more than 19 , divide it ; if n is non - zero ; Function to print a given number in words ; stores word representation of given number n ; handles digits at ten millions and hundred millions places ( if any ) ; handles digits at hundred thousands and one millions places ( if any ) ; handles digits at thousands and tens thousands places ( if any ) ; handles digit at hundreds places ( if any ) ; handles digits at ones and tens places ( if any ) ; long handles upto 9 digit no change to unsigned long long int to handle more digit number ; convert given number in words
< ? php $ one = array ( " " , " one ▁ " , " two ▁ " , " three ▁ " , " four ▁ " , " five ▁ " , " six ▁ " , " seven ▁ " , " eight ▁ " , " nine ▁ " , " ten ▁ " , " eleven ▁ " , " twelve ▁ " , " thirteen ▁ " , " fourteen ▁ " , " fifteen ▁ " , " sixteen ▁ " , " seventeen ▁ " , " eighteen ▁ " , " nineteen ▁ " ) ; $ ten = array ( " " , " " , " twenty ▁ " , " thirty ▁ " , " forty ▁ " , " fifty ▁ " , " sixty ▁ " , " seventy ▁ " , " eighty ▁ " , " ninety ▁ " ) ; function numToWords ( $ n , $ s ) { global $ one , $ ten ; $ str = " " ; if ( $ n > 19 ) { $ str . = $ ten [ ( int ) ( $ n / 10 ) ] ; $ str . = $ one [ $ n % 10 ] ; } else $ str . = $ one [ $ n ] ; if ( $ n != 0 ) $ str . = $ s ; return $ str ; } function convertToWords ( $ n ) { $ out = " " ; $ out . = numToWords ( ( int ) ( $ n / 10000000 ) , " crore ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 100000 ) % 100 ) , " lakh ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 1000 ) % 100 ) , " thousand ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 100 ) % 10 ) , " hundred ▁ " ) ; if ( $ n > 100 && $ n % 100 ) $ out . = " and ▁ " ; $ out . = numToWords ( ( $ n % 100 ) , " " ) ; return $ out ; } $ n = 438237764 ; echo convertToWords ( $ n ) . " STRNEWLINE " ; ? >