forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Convert numbers in letters

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Ammammata
Newbie


Joined: 03 Sep 2005
Posts: 3

PostPosted: Sat Sep 03, 2005 10:38 am    Post subject: Convert numbers in letters Reply with quote

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
View user's profile Send private message
jwfv
Valued Contributor
Valued Contributor


Joined: 19 Mar 2002
Posts: 422
Location: Beaufort, SC

PostPosted: Tue Sep 06, 2005 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue Sep 06, 2005 6:09 pm    Post subject: Reply with quote

Here's a quick example for converting up to 999.99:
http://forum.vdsworld.com/viewtopic.php?p=27749

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Ammammata
Newbie


Joined: 03 Sep 2005
Posts: 3

PostPosted: Tue Sep 06, 2005 10:05 pm    Post subject: Reply with quote

SnarlingSheep wrote:
Here's a quick example for converting up to 999.99:
http://forum.vdsworld.com/viewtopic.php?p=27749


Thankyou!
I'll try to add millions and thousands
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Sep 07, 2005 6:04 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Wed Sep 07, 2005 8:48 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Sep 07, 2005 8:59 am    Post subject: Reply with quote

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 Wink
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
View user's profile Send private message Send e-mail
jwfv
Valued Contributor
Valued Contributor


Joined: 19 Mar 2002
Posts: 422
Location: Beaufort, SC

PostPosted: Wed Sep 07, 2005 10:17 am    Post subject: Reply with quote

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
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Thu Sep 08, 2005 9:37 am    Post subject: Reply with quote

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 Wink

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
View user's profile Send private message
Ammammata
Newbie


Joined: 03 Sep 2005
Posts: 3

PostPosted: Thu Sep 08, 2005 3:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu Sep 08, 2005 3:37 pm    Post subject: Reply with quote

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 Wink

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group