Program to convert Number in characters | JavaScript program to convert number in characters ; To calculate the reverse of the number ; The remainder will give the last digit of the number ; Extract the first digit of the reversed number ; Match it with switch case ; Divide the number by 10 to get the next number ; Driver code
function NumbertoCharacter ( n ) { let rev = 0 , r = 0 ; while ( n > 0 ) { r = n % 10 ; rev = rev * 10 + r ; n = Math . floor ( n / 10 ) ; } while ( rev > 0 ) { r = rev % 10 ; switch ( r ) { case 1 : document . write ( " " ) ; break ; case 2 : document . write ( " " ) ; break ; case 3 : document . write ( " " ) ; break ; case 4 : document . write ( " " ) ; break ; case 5 : document . write ( " " ) ; break ; case 6 : document . write ( " " ) ; break ; case 7 : document . write ( " " ) ; break ; case 8 : document . write ( " " ) ; break ; case 9 : document . write ( " " ) ; break ; case 0 : document . write ( " " ) ; break ; default : document . write ( " " ) ; break ; } rev = Math . floor ( rev / 10 ) ; } } let n = 12345 ; NumbertoCharacter ( n ) ;