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 would like to be able to call the Quantity function with a null unit so that it returns the original dimensionless value. For example,

Quantity[3.0,"NoUnits"]

would return 3.0. Is there a dimensionless unit?

share|improve this question
    
If it isn't there, I assume you could just add a definition to Quantity. What use of that do you have in mind? –  Rojo Dec 21 '12 at 21:34
1  
@Rojo: I run Monte Carlo simulations which output huge quantities of data with varying dimensions, so I created a data dictionary which describes each data type, including the units. When the simulation results are loaded into Mathematica, I use the data dictionary to attach units. However, some of the data types are dimensionless and rather than having a special "dimensionless" case for the code that calls Quantity, I'd rather have Quantity handle it. –  David Skulsky Dec 21 '12 at 21:38

1 Answer 1

up vote 12 down vote accepted

I believe you can use "DimensionlessUnit" to get the desired result:

In[6]:= Quantity[3, "DimensionlessUnit"]

Out[6]= 3

(note this is the unit produced by QuantityUnit on a dimensionless value):

In[7]:= QuantityUnit[3]

Out[7]= "DimensionlessUnit"

share|improve this answer
    
Deleting my answer, +1 –  Rojo Dec 21 '12 at 21:58
    
Perfect! Thanks! –  David Skulsky Dec 21 '12 at 21:58
1  
@Rojo: I still found your answer helpful because it forced me to (finally) learn something about unprotecting symbols. I think you should keep your answer. –  David Skulsky Dec 21 '12 at 22:00

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.