Basic math can tell you that:
floor(log10(N))
The log base 10 of a number tells you approximately how many digits before the decimal are in that number.
For instance, 99987123459823754
is 9.998E+016
log10(99987123459823754)
is 16.9999441
, the floor of which is 16
- which can basically tell you "the exponent in scientific notation is 16, very close to being 17".
Floor always rounds down, so you don't need to worry about small exponents:
0.000000000003754 = 3.754E-012
log10(0.000000000003754) = -11.425
floor(log10(0.000000000003754)) = -12
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…