# How to get rid of trailing string after using Convert?

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.

• Convert does not appear to be a built-in Mathematica function. Are you using a package where Convert is defined? – DavidC 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

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

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.