| View previous topic :: View next topic |
| Author |
Message |
Ammammata Newbie
Joined: 03 Sep 2005 Posts: 3
|
Posted: Sat Sep 03, 2005 10:38 am Post subject: Convert numbers in letters |
|
|
I'm trying to translate a VBA script to convert numbers into letters:
7,123.45 = seven thousands one hundred twenty three (dollars) and forty five cents
I need it up to 999,999,999.99
Is there anything already done? I searched the forum 'convert', 'conversion', and similar but I found nothing.
TIA |
|
| Back to top |
|
 |
jwfv Valued Contributor

Joined: 19 Mar 2002 Posts: 422 Location: Beaufort, SC
|
Posted: Tue Sep 06, 2005 3:21 pm Post subject: |
|
|
I had to deal with this issue also. I had a Clipper program that I needed to translate to some other format.
I wound up doing the coding to produce "one thousand five hundred ... " in the report writer that I use rather than in VDS.
I would be happy to share the Clipper code to do it, but it sounds like you already have it in VB. As far as I know, no one else has accomplished this in VDS. _________________ Joe Floyd |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
|
| Back to top |
|
 |
Ammammata Newbie
Joined: 03 Sep 2005 Posts: 3
|
Posted: Tue Sep 06, 2005 10:05 pm Post subject: |
|
|
Thankyou!
I'll try to add millions and thousands |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Sep 07, 2005 6:04 am Post subject: |
|
|
Bored and can't sleep, so it works up to 999 trillion now.
Oh yeah.. and now that I did it, what's it for? lol
Just curious.. it's an interesting idea, just not sure for what. _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Wed Sep 07, 2005 8:48 am Post subject: |
|
|
| Quote: | | Bored and can't sleep, so it works up to 999 trillion now. |
just how long are the nights in your neck of the woods?
serge _________________
|
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Wed Sep 07, 2005 8:59 am Post subject: |
|
|
Way too long apparently.. because now I have this C code for Dread to add to his String DLL if he wants to.
Also here for anyone wanting to compare the two and see if it makes any sense to them
| Code: |
void Process3Digit(void)
{
// *** If number is one digit, get it's name from list 1 if @equal(@len(%%processnumber),1)
if (strlen(dollars) == 1)
{
strcpy(currtext,sSingle[atoi(dollars)-1]);
strcat(currtext," ");
return;
}
// *** If number is two digits and the first digit is 1, get name from list 2
if (strlen(dollars) == 2)
{
if (dollars[0] == '1')
{
strcpy(currtext,sDouble[((int)dollars[strlen(dollars)-2] - '0') - 1]);
strcat(currtext," ");
}
else
{
strcpy(currtext,sTens[((int)dollars[strlen(dollars)-3] - '0') - 2]);
strcat(currtext," ");
strcat(currtext,sSingle[((int)dollars[strlen(dollars)-2] - '0') - 1]);
strcat(currtext," ");
}
return;
}
if (strlen(dollars) > 2)
{
strcpy(currtext,sSingle[((int)dollars[strlen(dollars)-3] - '0') - 1]);
strcat(currtext," Hundred ");
strcat(currtext,sTens[((int)dollars[strlen(dollars)-2] - '0') - 2]);
strcat(currtext," ");
strcat(currtext,sSingle[((int)dollars[strlen(dollars)-1] - '0') - 1]);
strcat(currtext," ");
}
return;
}
void Num2Txt(void)
{
UCHAR tmpstr[256];
int pointplace = 0,thousands = 0,stop = 0;
// *** Get rid of commas before converting
double num = 6278567909520.333;
char * decPos;
// *** Format number to hundreths
sprintf(dollars,"%.2f",num);
// *** Split dollars and cents if necessary
decPos = strchr(dollars,'.');
if (decPos)
{
strcpy(cents,decPos);
cents[0] = cents[1];
cents[1] = cents[2];
cents[2] = '\0';
pointplace = strlen(dollars)-strlen(decPos);
dollars[pointplace] = '\0';
}
while(stop == 0) {
strcpy(tmpstr,currtext);
Process3Digit();
if (thousands == 1)
{
strcat(currtext," Thousand, ");
}
if (thousands == 2)
{
strcat(currtext," Million, ");
}
if (thousands == 3)
{
strcat(currtext," Billion, ");
}
if (thousands == 4)
{
strcat(currtext," Trillion, ");
}
strcat(currtext,tmpstr);
if (strlen(dollars) > 3)
{
dollars[strlen(dollars)-3] = '\0';
}
else
{
stop++;
}
thousands++;
}
strcat(currtext,"Dollars");
// *** Process cents if there is any
if (atoi(cents) > 0)
{
strcat(currtext," and ");
if (cents[1] != '0')
{
if (cents[0] == '0')
{
strcat(currtext,sSingle[((int)cents[1] - '0') - 1]);
}
else
{
strcat(currtext,sTens[((int)cents[0] - '0') - 2]);
strcat(currtext," ");
strcat(currtext,sSingle[((int)cents[1] - '0') - 1]);
}
}
else
{
strcat(currtext,sTens[((int)cents[0] - '0') - 2]);
}
strcat(currtext," Cents");
}
// *** Return results
strtrim(currtext);
MessageBox(NULL,currtext,"Num2Txt",MB_OK);
return;
}
|
_________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
jwfv Valued Contributor

Joined: 19 Mar 2002 Posts: 422 Location: Beaufort, SC
|
Posted: Wed Sep 07, 2005 10:17 am Post subject: |
|
|
Sheep -
Great work on the code! I'm not the author of the thread, but the use I had for this was for writing out the amounts on checks/drafts that my software printed. (Like Quickbooks does, for instance.) _________________ Joe Floyd |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Sep 08, 2005 9:37 am Post subject: |
|
|
| SnarlingSheep wrote: | Way too long apparently.. because now I have this C code for Dread to add to his String DLL if he wants to.
|
Thanks. I do, however, code in Delphi
But if I decide to put something like that into String.DLL, that code could easily be rewritten in Delphi.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Ammammata Newbie
Joined: 03 Sep 2005 Posts: 3
|
Posted: Thu Sep 08, 2005 3:07 pm Post subject: |
|
|
| SnarlingSheep wrote: | Bored and can't sleep, so it works up to 999 trillion now.
Oh yeah.. and now that I did it, what's it for? lol
Just curious.. it's an interesting idea, just not sure for what. |
Thankyou for the work, I didn't yet started it since I'm busy with a training
I'll use it in a Order Confirmation printout, for a customer in HK
Now I must configure it, reading the value from a file and writing the output to another file (I already did this in my previous - and still in development - routine: I'll just copy and paste few lines) |
|
| Back to top |
|
 |
SnarlingSheep Professional Member


Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Thu Sep 08, 2005 3:37 pm Post subject: |
|
|
| Dr. Dread wrote: | | SnarlingSheep wrote: | Way too long apparently.. because now I have this C code for Dread to add to his String DLL if he wants to.
|
Thanks. I do, however, code in Delphi
But if I decide to put something like that into String.DLL, that code could easily be rewritten in Delphi.
Greetz
Dread |
Doh.. that figures. Oh well, as long as it can be converted. _________________ -Sheep
My pockets hurt... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|