Re: Percentage Formating

• To: mathgroup at smc.vnet.net
• Subject: [mg111041] Re: Percentage Formating
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Sun, 18 Jul 2010 01:03:30 -0400 (EDT)

```You may be treading on dangerous ground here, since the percent sign %
in Mathematica refers to the preceding Output! So do be aware that with
some things you might do to include % in output, the result should be
regarded as just a display format and not as something you want to feed
into subsequent evaluations.

So here goes. Assuming you don't want to do your own conversion from
decimal fraction into percentage, I looked up "percent" in the
Documentation Center and found it in the Units package. Thus:

Needs["Units`"]

Convert[0.05263, Percent]
5.263 Percent

And then for the actual form you want, the most direct way is:

percentage = Convert[0.05263, Percent] /. Percent -> "%"
5.263 %

Notice that this output includes a space before the percent sign. That's
not just an accident, because there's actually a product there, as is
revealed by:

FullForm[percentage]
Times[5.263`,"%"]

And this means you CAN use this kind of percent representation in
further evaluation -- although I'd be cautious as to how far to go. For
example:

twice = 2 * percentage
10.526 %

To go back to decimals, you have to be careful, because at this point
the percent sign is being carried as just a text character. So you need
first to change that text character into the symbol Percent:

Convert[twice /. "%" -> Percent, Real]
0.10526

On 7/17/2010 8:16 AM, SMiranda wrote:
> There's an easy way of formating percentage numbers form reporting
> purposes...
> I mean... 0.05263 -->  5.26%
>
> Thanks !
>

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: Show left hand side
• Next by Date: Re: Combine matrices of equal height
• Previous by thread: Re: Percentage Formating
• Next by thread: Re: Percentage Formating