convert the integer part to a left justified string with no white space on the right. then depending on the length u can find the location of the digit, whether hundred/thousand and so on.
say the number is 15987
x=15987
length(x)=5 implies its part of thousand.
divide by 1000
remainder =987 (for second part) Quotient =15
alpha[15]=fifteen
add alpha[15] + thousand to a variable say words.
part - II
now x=987
divide by 100
quotient = 9
add alpha[9] + hundred to words
remainder=87
if remainder > 20
{divide by 10
add alpha(quotient + 20) to words
add alpha[remainder] to words
}
else
add alphs[remainder ] to words
expand this logic for the decimal part also by treating it to be integer in case u want to print decimal in words else simply print the decimal part/100 as required
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.