Re: Creating a Function to Display Numbers in Percent Format

• To: mathgroup at smc.vnet.net
• Subject: [mg128906] Re: Creating a Function to Display Numbers in Percent Format
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Mon, 3 Dec 2012 04:06:08 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <20121202095720.B81B86854@smc.vnet.net>

```Clear[percent]

percent[x_, numDec : _Integer?NonNegative : 1] :=
Row[{
PaddedForm[100 x, {500, numDec},
NumberPoint -> If[numDec == 0, "", "."],
DigitBlock -> {3, Infinity},
ExponentStep -> Infinity,
NumberPadding -> {"", "0"}],
"%"}]

Table[percent[.0237, n], {n, 0, 6}]

{2%, 2.4%, 2.37%, 2.370%, 2.3700%, 2.37000%, 2.370000%}

Bob Hanlon

On Sun, Dec 2, 2012 at 4:57 AM, Gregory Lypny
<gregory.lypny at videotron.ca> wrote:
> Hello everyone,
>
> I've written a function to display numbers in percent format.
>
> percent[x_, numDec_: 1] :=
>   PaddedForm[100 x, {500, numDec}, NumberPoint -> If[numDec == 0, "", "."],
>    DigitBlock -> {3, Infinity}, ExponentStep -> Infinity,
>    NumberSigns -> {{"-", "%"}, {"", "%"}}, NumberPadding -> {"", "0"}];
>
> The problem with it is that the padding on the right appears after the percent sign so that percent[.0237, 6] returns 2.37%0000.  What am I doing wrong?
>
> Regards,
>
> Gregory
>

```

• Prev by Date: Re: M8 parallel to M9 installation
• Next by Date: Re: Worldplot package
• Previous by thread: Creating a Function to Display Numbers in Percent Format
• Next by thread: Re: Creating a Function to Display Numbers in Percent Format