import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display,Math
display(Math('10^{-2} = 0.01'))
display(Math('10^{-1} = 0.1'))
display(Math('10^{0} = 1'))
display(Math('10^{1} = 10'))
display(Math('10^{2} = 100'))
print('Scientific notation')
display(Math('10,021: 1\\times10^{4} \\quad 1e+04'))
display(Math('2,119: 2\\times10^{3} \\quad 2e+03'))
display(Math('0.034: 3\\times10^{-2} \\quad 3e-02'))
x = 3984573945
display(Math('3.984574\\times10^{9}'))
print('{:,e}'.format(x))
print('{:,d}'.format(x))
print('%e' %x)
print('%.2e' %x)
s = '%e' %x
print(s)
print(type(s))
print(s[-2:])
Exercise
num = 2342
print('10**np.log10(abs(num)): ' + str(10**np.log10(abs(num))))
orderOfMag = int(np.floor(np.log10(abs(num))))
print('orderOfMag: ' + str(orderOfMag))
numstr = '{:,e}'.format(num)
print('numstr: ' + str(numstr))
wheredot = numstr.find('.')
print('wheredot: ' + str(wheredot))
scinot = numstr[:wheredot]
print('scinot: ' + str(scinot))
display(Math('%s \\text{ is } %s \\text { orders of magnitude } \\approx %s \\times 10^{%g}' \
%(num, orderOfMag,scinot,orderOfMag)))