Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Creating a Function to Display Numbers in Percent Format
Replies: 2   Last Post: Dec 4, 2012 4:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Gregory Lypny

Posts: 245
Registered: 3/14/05
Re: Creating a Function to Display Numbers in Percent Format
Posted: Dec 4, 2012 4:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Thanks Bob,

Good suggestion using Row because it allows for easier extraction of the actual number. My original fix used StringForm. Although, it is still not clear to me why appending a percent sign cannot be done through the second elements of each of the two lists in NumberSigns -> {{"-", "%"}, {"", "%"}}.

Gregory



On Sun, Dec 2, 2012, at 12:53 PM, Bob Hanlon <hanlonr357@gmail.com> wrote:

> 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@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
>>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.