Is there a way to obtain the order of magnitude of a number in Mathematica? E.g. 200 would have an order of magnitude of 2.
Asked
Active
Viewed 1,821 times
3 Answers
6
You're looking for RealExponent
. Strictly speaking, though, this is just as easily accomplished by Floor@Log[10, Abs[num]]
.

rcollyer
- 10,475
- 4
- 48
- 75
-
IntegerExponent doesn't give the order of magnitude. Try `IntegerExponent[2300]`. – kennytm Apr 20 '11 at 19:33
-
@wrongusername On the page guide/Syntax in the documentation center, you'll find a few more of these useful abbreviations, look under the 'Short forms' header. At first they tend to be confusing, but you'll discover they come in handy once you start doing _functional programming_ stuff (see guide/FunctionalProgramming). – Sjoerd C. de Vries Apr 20 '11 at 22:09
4
Start with
Log[10., 200]
2.30103
and use Round, Floor, Ceiling (or not) to taste.

Bobby Treat
- 101
- 2
2
Use IntegerLength to get the number of digits of an integer.
In[3]:= n=200;
In[4]:= IntegerLength[n] - 1
Out[4]= 2
Alternatively, if the number can be a non-integer, you could just use the log function
In[6]:= Floor[Log10[n]]
Out[6]= 2

kennytm
- 510,854
- 105
- 1,084
- 1,005
-
nit, `n` can be negative which means `Log10` will return a complex number. – rcollyer Apr 20 '11 at 19:39