Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I want to add 2 values :

ScientificForm[Quantity[0.6884806137833915, "Millimeters"], 2] + 
   ScientificForm[Quantity[0.0629737394087381, "Millimeters"], 2]

To get result

ScientificForm[Quantity[0.75, "Millimeters"], 2]


Small example, it seems more complicated because context and comments are lost. Idea here is, to get formula first and then after adding input data I get the values also. This works, but I want to keep only 2-3 most significant digits - here is where ScientificForm seems to be inapplicable.

enter image description here


l = a/b (Overscript[Subscript[s, 1], _] - 
     Overscript[Subscript[s, 2], _]);
m["Subscript[U, c](Overscript[l, _])"] = 
 Sqrt[(D[l, a] m["Subscript[U, C](a)"])^2 + (D[l, b] m[
       "Subscript[U, C](b)"])^2 + (D[l, 
       Overscript[Subscript[s, 1], _]] m[
       "Subscript[U, C](Subscript[s, 1])"])^2 + (D[l, 
       Overscript[Subscript[s, 2], _]] m[
       "Subscript[U, C](Subscript[s, 2])"])^2]
a = Subscript[na, 1] - Subscript[na, 2];
b = Subscript[nb, 1] - Subscript[nb, 2];
m["Subscript[U, C](b)"] = 
 m["Subscript[U, C](a)"] = 
  Sqrt[(m["Subscript[U, c](Subscript[na, 1])"]*
       D[a, {Subscript[na, 1]}])^2 + (m[
        "Subscript[U, c](Subscript[na, 2])"]*
       D[a, {Subscript[na, 2]}])^2]
m["Subscript[U, C](Subscript[s, 2])"] = 
 m["Subscript[U, C](Subscript[s, 1])"] = (Sqrt[(Subscript[
         t, \[Infinity], \[Beta]] Subscript[e, p, kruvik]/
         3)^2 + (\[Beta] Subscript[L, kruvik])^2])
m["Subscript[U, c](Subscript[nb, 2])"] = 
 m["Subscript[U, c](Subscript[nb, 1])"] = 
  m["Subscript[U, c](Subscript[na, 2])"] = 
   m["Subscript[U, c](Subscript[na, 1])"] = 
          t, \[Infinity], \[Beta]] Subscript[e, p, joonlaud]/
          3)^2 + (\[Beta] Subscript[L, joonlaud])^2]
\[Beta](*usaldatavus*)= 0.95;
   t, \[Infinity], \[Beta]](*studenti tegur*)= \
     InverseCDF[StudentTDistribution[10000], \[Beta]], 0.1]\);
Subscript[t, v, \[Beta]]= 
  Round[InverseCDF[StudentTDistribution[v], \[Beta]], 0.1];
Subscript[e, p, kruvik]= 
  Quantity[0.004, "Millimeters"];
Subscript[L, kruvik]= 
  Quantity[0.005, "Millimeters"];
Subscript[L, joonlaud]= 
  Quantity[0.5, "Millimeters"];
Subscript[e, p, joonlaud]= 
  Quantity[0.2, "Millimeters"];
a = Subscript[na, 1] - Subscript[na, 2];
b = Subscript[nb, 1] - Subscript[nb, 2];
a = Quantity[0.78, "Meters"]; 
b = Quantity[0.112, "Meters"]; 
Subscript[s, 1] = {Quantity[3.67, "Millimeters"], 
   Quantity[3.63, "Millimeters"], Quantity[3.65, "Millimeters"], 
       Quantity[3.65, "Millimeters"]}; 
Subscript[s, 2] = {Quantity[2.82, "Millimeters"], 
   Quantity[2.8, "Millimeters"], Quantity[2.8, "Millimeters"], 
       Quantity[2.8, "Millimeters"]}; 
Overscript[Subscript[s, 1], _] = Mean[Subscript[s, 1]];
Overscript[Subscript[s, 2], _] = Mean[Subscript[s, 2]];
m["Subscript[U, c](Overscript[l, _])"]
m["Subscript[U, C](Subscript[s, 2])"]
m["Subscript[U, C](b)"]
m["Subscript[U, c](Subscript[nb, 2])"]
share|improve this question
Do you want to keep all expressions in ScientificForm[]? The computation works if we do e.g. n1 = ScientificForm[Quantity[0.6884806137833915, "Millimeters"], 2]; n2 = ScientificForm[Quantity[0.0629737394087381, "Millimeters"], 2]; ScientificForm[First@n1 + First@n2, 2] – Eric Thewalt Mar 20 '13 at 0:24
Do you want to keep all expressions in ScientificForm[]? Yes. Computation does not work in my case, where i first compute the formula and then answer. I use variable 'm' as hashmap to store unified errors in scientific form and function First would be applied in formula computation. I could probably use HoldForm / ReleaseHold, but that would create a layer of extra complexity. – Margus Mar 20 '13 at 0:54
Could you expand your question with the above information and a minimal example of this behaviour? That is, define a (shortened) hash map and show the kind of operation you're attempting, and the output you're getting. – Eric Thewalt Mar 20 '13 at 6:00
up vote 5 down vote accepted

One possibility is to first do:

 $Post = Function[n, n /. Quantity[r_?NumberQ , unit_] :> 
                          Quantity[ScientificForm[r, 2], unit]];


 Quantity[0.6884806137833915, "Millimeters"] + 
 Quantity[0.0629737394087381, "Millimeters"]

results in

Mathematica graphics

and also your small example works.

share|improve this answer

If you wish to style all numbers with ScientificForm you should proceed as Rolf Mertig shows, but if you only want to affect a specific set of objects you could use UpValues, perhaps like this:

With[{SF = ScientificForm},
    (#[SF[a_, n1_], SF[b_, n2_], c___] ^:= SF[a ~#~ b, Max[n1, n2]] ~#~ c) &,
    {Plus, Times, Power}
share|improve this answer

Your Answer


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.