I am using Quantities (units) in Mathematica 11.3 and would like to express the numerical portion of the output in scientific notation. The command ScientificForm[quantity] does not work.

  • 2
    $\begingroup$ Example code please. $\endgroup$ – Henrik Schumacher Mar 3 '19 at 17:31
  • 2
    $\begingroup$ Typically the output is scientific notation - for instance Quantity[0.000000000000009, "Joules"] has the output Quantity[9.\[CenterDot]10^-15, "Joules"]. If you're using something like Quantity[9/Pi*-1000000, "Joules"], you may need to do N@Quantity[9/Pi*-1000000, "Joules"], which results in the output Quantity[-2.86479\[CenterDot]10^6, "Joules"]. $\endgroup$ – Carl Lange Mar 3 '19 at 17:38
  • 2
    $\begingroup$ Does ScientificForm[N @ quantity] do what you want? $\endgroup$ – Carl Woll Mar 3 '19 at 23:57

When the argument to Quantity is in arbitrary precision (e.g. an exact integer), it does not get converted automatically to scientific notation. You can force the conversion if you numericize the input, converting it e.g. to machine precision:

Quantity[2000000, "Kilograms"]
N @ Quantity[2000000, "Kilograms"]

exact output

numerical output in scientific notation

Note that, however, even machine precision numbers whose exponents are "small" according to some preset threshold do not get converted to scientific notation.

Quantity[2000., "Kilograms"]

2000 does not get converted

I have not (yet) found a way to force that conversion at will.

  • 2
    $\begingroup$ Looking at some DVs (QuantityUnits`Private`makeNumberValue) it looks like the 10^6 cutoff is hardcoded... $\endgroup$ – b3m2a1 Mar 4 '19 at 0:40
  • $\begingroup$ @b3m2a1 Interesting, thank you for digging it up. It's unfortunate that the cutoff is hardcoded. $\endgroup$ – MarcoB Mar 4 '19 at 1:30
  • 2
    $\begingroup$ On the other hand this should work (it does for me): Quantity[ScientificForm[10.^5], "USDollars"] $\endgroup$ – b3m2a1 Mar 4 '19 at 1:31
  • $\begingroup$ @b3m2a1 ... as does, interestingly, ScientificForm[N@Quantity[1000, "Kilograms"]] which, I see now, was suggested by Carl Woll in comment. $\endgroup$ – MarcoB Mar 4 '19 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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