Selecting a Free-Form input cell with the mouse I can query something like:

convert 1 atm to pascals

and get as a result

101\[ThinSpace]325\[ThickSpace]Pa (pascals)

I can take that number and manually enter it into a variable (I can't cut and paste it since the space turns the cut and pasted value into (101)(325)).

Is there a way to just extract the numeric portion of the result and assign it to a variable?


2 Answers 2


You can use a slightly different query: (convert 1 atm to pascals)/pascals

enter image description here

The number in this case is a regular number (not a string or some other exotic construction.)

If you instead use Wolfram|Alpha query (shortcut ==), you get a lot of results:

enter image description here

with a + icon on the right of each. Clicking on the + gives a menu where you can choose a format:

enter image description here

In particular the 'Number data' format will then paste something like

WolframAlpha["convert 1 atm to pascals", {{"Result", 1}, "NumberData"}]

into the notebook. This doesn't help you much the first time, but can be used programmatically for subsequent calculations.

  • $\begingroup$ WolframAlpha["(convert 1 atm to pascals)/pascals", {{"Result", 1}, "NumberData"}] works very nicely. Thanks! $\endgroup$ Mar 4, 2012 at 5:30

I am not sure there is a simple solution to this.

enter image description here
enter image description here

result = %;
result //FullForm

WolframAlphaResult["convert 1 atm to pascals", List[List["Result", 1], "Content"]]

Copy As... and various other attempts to get at the result don't work.

Interestingly, copying and pasting the result into somewhere other than Mathematica (e.g. an answer window here) gives the following, which suggests a way around the issue.

FrameBox[    StyleBox[    FormBox[    StyleBox[    RowBox[{
RowBox[{"101", "\[ThinSpace]", "325"}], " ", " ", "\[ThickSpace]",   " ", 
StyleBox["\<\"Pa\"\>",  FontFamily->"Helvetica",  FontSize->Smaller], " ", 
RowBox[{"\<\"(\"\>", "", "\<\"pascals\"\>", "", "\<\")\"\>"}],
StripOnInput->False, LineIndent->0,
LinebreakAdjustments->{1, 100, 1, 0, 100},
LineColor->GrayLevel[0.6], FrontFaceColor->GrayLevel[0.6], BackFaceColor->GrayLevel[0.6],
GraphicsColor->GrayLevel[0.6],   FontFamily->"Helvetica",
FontSize->Smaller,  FontColor->GrayLevel[0.6]]}], ZeroWidthTimes->False,  LineIndent->0,
LinebreakAdjustments->{1, 100, 1, 0, 100}],
TraditionalForm], "Output",
ScriptLevel->0, FontFamily->"Times", FontSize->14, Background->None],
BaseStyle->{Plain}, FrameMargins->10, FrameStyle->GrayLevel[0.85], RoundingRadius->5,

The part specification might be specific to the case in question, but something like the following seems to work.

 StringReplace[ToBoxes[result][[1, 1, 1, 1, 1, 1, 1, 1, 1]], 
  x__ ~~ "\[ThinSpace]" ~~ y__ :> x ~~ y]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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