Re: Number formatting for financial applications
- To: mathgroup at smc.vnet.net
- Subject: [mg27485] Re: Number formatting for financial applications
- From: "Paul Lutus" <nospam at nosite.com>
- Date: Thu, 1 Mar 2001 03:53:11 -0500 (EST)
- References: <97ff8t$fuq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Felipe" <no at spam.com> wrote in message news:97ff8t$fuq at smc.vnet.net... > > I am having a hard time getting the format I need in my output. For some > reason Mathematica keeps putting things in engineering form when I just want > a long number > > e.g. I want to display this number > > 101522688.1906242 > > like this > > $ 101,522,688.1906242 (I can do without the $ if it's too hard) > > How can I achieve this without writing ten different tags each time. I just > want to have a formula with this output instead of having to wrap the > formula with AccountingForm[], NumberForm[], DigitBlock, etc. It looks > really ugly when I print it. Why don't you write a function that encapsulates the formatting you need, instead of "wrap[ping] the formula with AccountingForm[], NumberForm[], DigitBlock, etc."? The idea of a function is to create and optimize a series of operations just once, then call the function from elsewhere with predictable results and little further effort. nf[x_,pl_,w_] := Module[ {a,b}, a = IntegerPart[x]; a = PaddedForm[a,w,DigitBlock->3]; b = FractionalPart[x]; b = Round[b 10^pl]; b = ToString[b]; While[StringLength[b]<pl,b= b<>"0"]; StringForm["$`1`.`2`",a,b] ]; SetAttributes[nf,Listable]; data = {101522688.1906242,1234,12.99,345.678}; nf[data,2,9]//TableForm $ 101,522,688.19 $ 1,234.00 $ 12.99 $ 345.68 nf[data,4,9]//TableForm $ 101,522,688.1906 $ 1,234.0000 $ 12.9900 $ 345.6780 -- Paul Lutus www.arachnoid.com