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.
Convert[0.05263, Percent] /. Percent -> "%"

I would like to remove the trailing "%" but if I put Percent->"" it concatenates a literal empty pair of quotes.

Thanks.

Edit: I should have explained it works well in the Mathematica interactive evaluator but not in an InputField where it will concatenate the said quotes.

share|improve this question
    
Convert does not appear to be a built-in Mathematica function. Are you using a package where Convert is defined? –  David Carraher Apr 26 '13 at 12:25
    
Perhaps pre-9 Units package? –  cormullion Apr 26 '13 at 12:33
    
Yes I am using Units. So my code has a Needs["Units`"]. I am using Mathematica 9. –  dabd Apr 26 '13 at 12:36
add comment

2 Answers

For the older "Units`" package units are just symbols which are multiplied to numbers. If you want to get rid of them, just replace them with 1:

 Convert[0.05263, Percent] /. Percent -> 1

In such cases, it is often very useful to use InputForm or even FullForm to explicitly check with what you are dealing and what is returned, e.g.:

 Convert[0.05263, Percent] /. Percent -> 1 // FullForm

which shows that now the number is all that's left, without any spurious relicts of the former units caculation...

share|improve this answer
add comment

You can the following to check the FullForm of your code (makes it easy to understand how Mathematica's internal structures works. Check Mathematica's reference if you want to know details about this.

FullForm[Convert[0.05263, Percent]]
(* Result: Times[5.263`,Percent] *)

There you see that it is a simple multiplication (Head: Times) of two elements. Then you can either use Albert Retey's solution or do a simple

First[Convert[0.05263, Percent]]
(* Result: 5.263 *)

This is especially usefull if you have a more complex output like

FullForm[SpeedOfLight]
(* Result: Times[299792458,Meter,Power[Second,-1]] *)

Then you can do a quick

First[SpeedOfLight]
(* Result: 299792458 *)

to get the value of this expression without the units.

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.