Near the middle of the semester in chemistry, we get problems like:
Convert 1.283850057 to Scientific Notation
Convert 3.583✕106 to Standard Notation
This is just stupid busy work for people who already know how to do this. So…
Given an input in any reasonable, convenient format, in either standard notation or scientific notation, output the same number in the other notation. However, note that
e will not be accepted in place of
*10^, as this gives a significant advantage to languages with builtins with
If not otherwise specified, standard notation will take this format:
x (an integer) xxxxxxxxxx (a large integer with no more than 10 digits) x.xxxx (a float) x.xxxxxxxxxx (a float with no more than 10 x's after the decimal point)
While scientific notation will take this format:
x*10^x x.zzzz*10^z (x will be >= 1) x*10^-x x.zz*10^-xx (x will be >= 1)
Input will never contain more than 10 leading+10 trailing digits, and you may decide how to deal with trailing zeroes after the decimal point. The exponent will never be so large as to max out your language's allowance for large numbers. You should only need to handle up to about 1010.
input => output ---scientific to standard--- 4.5*10^7 => 45000000 1*10^0 => 1 8.9*10^-2 => 0.089 1.0001*10^5 => 100010 9.999999*10^9 => 9999999000 4.00038*10^2 => 400.038 ---standard to scientific--- 7354 = 7.354*10^3 385.43 => 3.8543*10^2 0.32 = 3.2*10^-1 0.00044 => 4.4*10^-4 0.053 => 5.3*10^-2
As always, standard loopholes are disallowed. This is code-golf, so shortest bytes wins!