Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert numeric check amount to word equivalent

Status
Not open for further replies.

sylma4

MIS
Mar 18, 2002
1
US
I am trying to find an algorithm to solve the following problem:

1. User enters amount of check (i.e. 242.10)
2. Program outputs word equivalent of amount (i.e. TWO HUNDRED FORTY TWO and 10/100)

Thanks,
 
u have to write a function for converting the integer and the decimal parts separately. create an array as follows

alpha[0]=zero
alpha[1]=one
alpha[2]=two
.
.
.
.
.
alpha[20]=twenty
alpha[21]=thirty
.
.
.
.
.
.
alpha[28]=hundred
alpha[29]=thousand
.
.

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


icici


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top