Created
September 10, 2018 21:37
-
-
Save svenk/5bddb4e3484e93ebc71b97574779de60 to your computer and use it in GitHub Desktop.
Python: Display scientific number with 10 power something (suitable for LaTeX) instead of the "e" suffix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
sci = lambda d: re.sub(r'e\+?(-?)?0?(\d+)', r" x 10^{\1\2}" ,"%.2e"%d) | |
""" | |
### Examples: | |
In [34]: sci(1) | |
Out[34]: '1.00 x 10^{0}' | |
In [35]: sci(123456) | |
Out[35]: '1.23 x 10^{5}' | |
In [36]: sci(0.0000123456) | |
Out[36]: '1.23 x 10^{-5}' | |
In [37]: sci(0.0033456) | |
Out[37]: '3.35 x 10^{-3}' | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment