How to dequantify units in mathematica?

Oops - found it! QuantityMagnitude[quantity] does the job. For example,

In[1]:= QuantityMagnitude[Quantity[1, "Feet"]]

Out[1]= 1

To temporary disable Quantity for all of your functions,

SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False];

In[5]:= DateDifference[DateList[{2017, 11, 11}], DateList[]]
Out[5]= Quantity[-21.5912, "Days"]
In[6]:= oldSystemOptions = SystemOptions["DataOptions"]; 
        SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False];
In[7]:= DateDifference[DateList[{2017, 11, 11}], DateList[]]
Out[7]= -21.5908

This is a neat trick to use. This works on Mathematica 10 & 11. Or simply use First.

In[12]:= First@DateDifference[DateList[{2017, 11, 11}], DateList[]]
Out[12]= -21.5869 

As already mentioned, the function you're looking for is QuantityMagnitude. However, I think single argument QuantityMagnitude is error prone. It is much better to give it a second argument:

QuantityMagnitude[Quantity[1, "Feet"]]
QuantityMagnitude[Quantity[1, "Feet"], "Meters"]
QuantityMagnitude[Quantity[1, "Feet"], "Seconds"]

1

381/1250

Quantity::compat: Feet and Seconds are incompatible units

QuantityMagnitude[Quantity[1, "Feet"], "Seconds"]

Tags:

Units