Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the list

m = {{x == 0, y == 0.29264681456942615}, {x == 30 , y == 0.2419119568894183},
     {x == 50 , y == 0.1485164898707659}, {x == 70 , y == 0.05437093382683481},
     {x == 90 , y == 1.`}} 

and I want to change the unit into percent only for y value. So the output that I want will be

m = {{x == 0, y == 29.264681456942615%}, {x == 30 , y == 24.19119568894183%},
     {x == 50 , y == 14.85164898707659%}, {x == 70 , y == 5.437093382683481},
     {x == 90 , y == 100%}} 

How can I do this??

share|improve this question
    
So in the new list the entries y== will contain strings (not numbers) ? –  b.gatessucks Nov 7 '12 at 10:06
    
It doesn't matter –  Sungjin Lee Nov 7 '12 at 10:08
    
If you don't need the "%" symbol you can just do : m /. {y == x_ -> y == 100 x}. –  b.gatessucks Nov 7 '12 at 10:27
    
If you need the "%" symbol you can do m /. {y == x_ -> y == ToString[100 x]<>"%"} –  PlatoManiac Nov 7 '12 at 10:29
    
@b.gatessucks Sorry I did not test it just commented. This will work m /. {y == x_ -> y == Hold[ToString[Evaluate[100 x]] <> " %"]} // Release –  PlatoManiac Nov 7 '12 at 11:08
show 1 more comment

2 Answers

StringForm[] works nicely for this:

m /. y == n_?NumericQ :> y == StringForm["`1`%", InputForm[100 n]]
   {{x == 0, y == 29.264681456942615%}, {x == 30, y == 24.19119568894183%},
    {x == 50, y == 14.85164898707659%}, {x == 70, y == 5.437093382683481%},
    {x == 90, y == 100.%}}
share|improve this answer
add comment
 m /. y == y1_ :> y == ToString[100 y1] <> "%"

or

m /. y == x_ :> y == Row[{100 x, "%"}]

or

m /. y == x_ :>  y == AccountingForm[100 x, 6, NumberPadding -> {"", "%"}]

all give

{{x == 0, y == "29.2647%"}, {x == 30, y == "24.1912%"}, 
  {x == 50,y == "14.8516%"}, {x == 70, y == "5.43709%"}, {x == 90,  y == "100.%"}}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.