How does Mathematica determine when to use scientific notation?

I have code that takes an initial guess for a set of parameters to use in a function that I want to minimize, calculates the function, prints the value, recalculates new parameters via the gradient descent method, recalculates the function, prints it, and so on.

This is what my output looks like: I don't mind it, I'm just curious as to when Mathematica decides it should use scientific notation and when it thinks regular notation is fine. At first sight, it seems random.

MWE not necessary because this is not a question related to code.

Edit: Sorry for the huge image. I've replaced it with a smaller one.

• You can use NumberForm[] with its ScientificNotationThreshold setting if you want more control. – J. M. will be back soon Sep 27 '18 at 13:06
• I know I can. As I said, I don't mind which notation Mathematica uses for this; I'm just curious as to how it determines which one to use. – Rain Sep 27 '18 at 13:07
• I don't have your numbers, so I can only hazard a guess that it's about precision differences. See e.g. {97170., 97170.5, 97170.4}. – J. M. will be back soon Sep 27 '18 at 13:12
• I suspect the message formatting is using the same thresholds as NumberForm. – Daniel Lichtblau Sep 27 '18 at 13:28

Mathematica uses 2 criteria to determine whether to show a number in scientific notation or not.

1. For both arbitrary precision and machine precision numbers, use scientific notation if the exponent is not between 5 and -5 inclusive:

123456.
1234567.

123456.

1.23457*10^6

and:

1.23456*^-5
1.23456*^-6

0.0000123456

1.23456*10^-6

2. For arbitrary precision numbers, use scientific notation if the number of digits displayed is more than the precision:

1234004
1234005
123400`6

1.234*10^5

1.2340*10^5

123400.

Basically, if Mathematica used decimal notation for all 3, then it would look like:

123400.

123400.

123400.

That is, the outputs would be indistinguishable. By using scientific notation, Mathematica is indicating the actual precision of the number.

• Thank you. I think this explains it. I guess it has to do with whether the number has zeroes or not after the displayed digits (which are always five, I think). – Rain Sep 27 '18 at 22:46