20
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ If it isn't there, I assume you could just add a definition to Quantity. What use of that do you have in mind? $\endgroup$
    – Rojo
    Commented Dec 21, 2012 at 21:34
  • 1
    $\begingroup$ @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. $\endgroup$
    – Cassini
    Commented Dec 21, 2012 at 21:38

1 Answer 1

27
$\begingroup$

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

Quantity[3, "DimensionlessUnit"]
3

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

QuantityUnit[3]
"DimensionlessUnit"
$\endgroup$
3
  • $\begingroup$ Deleting my answer, +1 $\endgroup$
    – Rojo
    Commented Dec 21, 2012 at 21:58
  • $\begingroup$ Perfect! Thanks! $\endgroup$
    – Cassini
    Commented Dec 21, 2012 at 21:58
  • 3
    $\begingroup$ @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. $\endgroup$
    – Cassini
    Commented Dec 21, 2012 at 22:00

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.