0

Using python, I am trying to print floats in the format of 0.####e#. For example, 1234.56 is converted to 0.123456e4 or .321 is converted to 0.321e0 etc. I am surprised that an extensive search has not produced any sample code for this exercise. As far as I can tell, neither Display a decimal in scientific notation or stackoverflow.com/questions/53274821/… address converting a number like 1234.56 into 0.123456e4.

If possible, I would like to use the python f-string to do the conversion. But any solution is very welcomed.

GAF
  • 301
  • 3
  • 9
  • The linked answer isn't a direct duplicate, but this one is https://stackoverflow.com/questions/53274821/scientific-notation-formatting-in-python – Simon Notley Sep 11 '19 at 20:32
  • Neither one of the suggested answers addresses my question. I see nothing in those answers that takes a number like 1234.56 and convert it to 0.123456e4. – GAF Sep 12 '19 at 11:23
  • There isn't a straight-up f string that gives this exact format, the closest you could get is 1.2345e+3, but the answer I linked shows how to make a function using two f strings. You should be able to alter it a tiny bit to get your preferred format – Simon Notley Sep 12 '19 at 18:13

0 Answers0