Hi All,

I would do this a little differently. I would pass in number (real)
convert to text using commas and decimal points
build an array of each second so if you passed in and got the following string
111,111,222,333,444.26
you array would look like this
111
111
222
333
444.26
I would then separate last array using decimal point yielding
$decimal := 26

you array would look like this
111
111
222
333
444

Based upon size of array you have billions etc

Regards

Chuck






On Tue, Jun 16, 2020 at 5:44 PM David Adams via 4D_Tech
<[email protected]> wrote:
>
> Thanks!
>
> On Wed, Jun 17, 2020 at 1:08 AM Keith Culotta <[email protected]>
> wrote:
>
> > This was written for v6 a while back.  The app is still being used believe
> > it or not.
> >
> > =====================================
> >   // METHOD: DtoS - Dollar to String - kc 3/1/00
> >   // INPUT: real - dollar to convert to string
> >   // was -> $0:=String($1;"$###,###,###,##0.00")
> >
> > String(200;$0)
> > _O_C_INTEGER($i;$sec)
> > C_REAL($partVal)
> >
> > _O_ARRAY STRING(12;mag1;20)  //  this should be be declared elsewhere
> > _O_ARRAY STRING(12;mag2;8)
> > _O_ARRAY STRING(12;mag3;4)
> > mag1{0}:=""
> > mag1{1}:=" One"
> > mag1{2}:=" Two"
> > mag1{3}:=" Three"
> > mag1{4}:=" Four"
> > mag1{5}:=" Five"
> > mag1{6}:=" Six"
> > mag1{7}:=" Seven"
> > mag1{8}:=" Eight"
> > mag1{9}:=" Nine"
> > mag1{10}:=" Ten"
> > mag1{11}:=" Eleven"
> > mag1{12}:=" Twelve"
> > mag1{13}:=" Thirteen"
> > mag1{14}:=" Fourteen"
> > mag1{15}:=" Fifteen"
> > mag1{16}:=" Sixteen"
> > mag1{17}:=" Seventeen"
> > mag1{18}:=" Eighteen"
> > mag1{19}:=" Nineteen"
> >
> > mag2{1}:=" Twenty"
> > mag2{2}:=" Thirty"
> > mag2{3}:=" Forty"
> > mag2{4}:=" Fifty"
> > mag2{5}:=" Sixty"
> > mag2{6}:=" Seventy"
> > mag2{7}:=" Eighty"
> > mag2{8}:=" Ninety"
> >
> > mag3{1}:=" "
> > mag3{2}:=" Thousand"
> > mag3{3}:=" Million"
> > mag3{4}:=" Billion"
> >
> > $theNum:=$1  //  Num(Request("a Number"))
> > $Target:=String(Trunc($theNum;0))
> > $TLength:=Length($Target)
> > $sec:=1
> > $theOutput:=""
> > While (Length($Target)>0)
> >         $partVal:=Num(Substring($target;Length($target)-3+1;3);$sec)
> >         If ($partVal=0)
> >                 $theOutput:=" "+$theOutput
> >         Else
> >                 $theOutput:=DtoS_Get3
> > (Substring($target;Length($target)-3+1;3);$sec)+mag3{$sec}+$theOutput
> >         End if
> >         $target:=Substring($Target;1;Length($target)-3)
> >         $sec:=$sec+1
> > End while
> > $cents:=String(Round(Round($theNum;2)-Trunc($theNum;0);2);"#.00")
> > $cents:=Substring($cents;2;2)
> > $theOutput:=$theOutput+"Dollars and "+$cents+"/100"
> >
> >
> > $theOutput:=Replace string($theOutput;"  ";" ")  // extra spaces may
> > appear for "000"
> > $0:=Replace string($theOutput;"  ";" ")
> >
> >
> > =====================================
> >   // METHOD: DtoS_Get3 - return words for a 3 digit section xxx,XXX,xxx
> >   // INPUT1: string - 0..999
> >   // INPUT2: integer - what 3 digit section are we in ...3,2,1
> >
> > _O_C_STRING(3;$1)
> > _O_C_STRING(200;$0)
> > _O_C_INTEGER($numValueR2;$numValueR1;$numValueM2;$2)
> >
> > While (Length($1)<3)
> >         $1:="0"+$1
> > End while
> >
> > $numValueR2:=Num(Substring($1;2;2))
> > $numValueR1:=Num(Substring($1;3;1))
> > $numValueM2:=Num(Substring($1;2;1))
> > $numValueL1:=Num(Substring($1;1;1))
> >
> > If ($numValueR2<20)  //  handle the rightmost 2 digits
> >         $0:=mag1{$numValueR2}
> > Else
> >         $0:=mag2{$numValueM2-1}+mag1{$numValueR1}
> > End if
> >
> > If ($numValueL1>0)
> >         $0:=mag1{$numValueL1}+" Hundred"+$0
> > End if
> >
> > Keith - CDI
> >
> > > On Jun 16, 2020, at 4:48 AM, David Adams via 4D_Tech <
> > [email protected]> wrote:
> > >
> > > I'm looking for code that converts something like this:
> > >
> > > 24120.10 into something like this:
> > >
> > > twenty-four thousand, one hundred and twenty point one
> > >
> > > The hope is to emulate Python's num2words.
> > >
> > > I figure anyone who had to write a check printing feature years ago might
> > > have something along these lines, and may be willing to share. I'm not
> > > trying to print checks, that's just an example.
> > >
> > > Definitely after native code, hoping to avoid a PHP call.
> > >
> > > For reference, Dani Beaubien sent me a link to an old post from Garri
> > Ogata
> > > with something like the code I'm asking about:
> > >
> > >
> > >
> > http://4d.1045681.n5.nabble.com/Number-To-Text-native-4D-code-td4864780.html
> > >
> > > I also found what looks like a version of that code here:
> > >
> > > https://kb.4d.com/assetid=76423
> > >
> > > This version has a bunch of extra ) characters, but runs once you fix
> > them.
> > > However, this code does *not* include decimals. I'd like to keep the
> > > decimals part.
> > >
> > > Thanks for any help.
> > > **********************************************************************
> > > 4D Internet Users Group (4D iNUG)
> > > New Forum: https://discuss.4D.com
> > > Archive:  http://lists.4d.com/archives.html
> > > Options: https://lists.4d.com/mailman/options/4d_tech
> > > Unsub:  mailto:[email protected]
> > > **********************************************************************
> >
> >
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> New Forum: https://discuss.4D.com
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[email protected]
> **********************************************************************



--
-----------------------------------------------------------------------------------------
 Chuck Miller Voice: (617) 739-0306 Fax: (617) 232-1064
 Informed Solutions, Inc.
 Brookline, MA 02446 USA Registered 4D Developer
       Providers of 4D, Sybase & SQL Server connectivity
          https://www.informed-solutions.com
-----------------------------------------------------------------------------------------
This message and any attached documents contain information which may
be confidential, subject to privilege or exempt from disclosure under
applicable law.  These materials are intended only for the use of the
intended recipient. If you are not the intended recipient of this
transmission, you are hereby notified that any distribution,
disclosure, printing, copying, storage, modification or the taking of
any action in reliance upon this transmission is strictly prohibited.
Delivery of this message to any person other than the intended
recipient shall not compromise or waive such confidentiality,
privilege or exemption from disclosure as to this communication.
**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to