Is it really this hard to print currency values?

dunbarx at aol.com dunbarx at aol.com
Mon Jul 30 11:22:10 EDT 2012


Hi.


You have replies, and can see that the task is one of parsing characters into a useful form.


This is a function I wrote in HC a long time ago to relieve the tedious task of writing out the text of a number when issuing checks. It should be instructive, as it sort of acts in the same way. You call it as:  digitToWord(yourNumericalValue):



function digitToWord theDigits
  put "One,Two,Three,Four,Five,Six,Seven,Eight,Nine" into ones
  put "Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,"¬
  & "Eighteen,Nineteen" into teens
  put ",Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety" into tens
  set numberformat to "#.00"
  get offset(".",theDigits)
  if it ‚ 0 then
    put " Dollars and" && char it + 1 to it + 2 of theDigits & "/100" into
temp
    delete char it to it + 2 of theDigits
  end if
  
  get number(chars of theDigits)
  if char it - 1 of theDigits = 1 then put item char it of theDigits + 1 of
teens before temp
  else
    put item char it of theDigits of ones before temp
    put item char it - 1 of theDigits of tens & space before temp
  end if
  
  if it „ 3 then put item char it - 2 of theDigits of ones && "Hundred" &
space before temp
  if it = 4 then put item char it - 3 of theDigits of ones && "Thousand" &
space before temp
  if it = 5 then put item char it - 4 of theDigits of tens && "Thousand" &
space before temp
  if it = 6 then
    put item char 1 of theDigits of ones && "Hundred" && item char 2 of
theDigits of tens && item char 3 of theDigits of ones & " Thousand " before
temptemp
  end if
  
  return temp
end digitToWord



-----Original Message-----
From: dunbarx <dunbarx at aol.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Sun, Jul 29, 2012 12:30 pm
Subject: Re: Is it really this hard to print currency values?


Hi.


I wrote a checkWriting stack in HC about 25 years ago. No modulo, just text 
parsing. It is compact and utterly basic. If nobody else replies in the next 
day, I will pull it from my office and send you the code. It is just chunk 
engineering. Fun stuff.


Craig Newman



-----Original Message-----
From: Dr. Hawkins <dochawk at gmail.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Sun, Jul 29, 2012 12:09 pm
Subject: Is it really this hard to print currency values?


As I sat down to finally encode currency into my output, I pulled old
answers from older questions and did more searches.

Is it *really* this hard to output currency?

To turn 123456.78 into $123,456.78, everything I'm finding would have
me using modulo arithmetic to produce three values, with these three
values being output in the string (4, actually, to allow values in the
millions).

Am I missing something obvious here?
-- 
The Hawkins Law Firm
Richard E. Hawkins, Esq.
(702) 508-8462
HawkinsLawFirm at gmail.com
3025 S. Maryland Parkway
Suite A
Las Vegas, NV  89109

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 



More information about the use-livecode mailing list