0

I'm trying to print a very small p-value to a plot (p-value = 4.3289045262877305e-11). I need to round it to have fewer digits after the decimal so it will fit (4.33e-11) but when I'm using round(,3) it returns 0.0. How can I return the number like this 4.33e-11?

ksohan
  • 1,165
  • 2
  • 9
  • 23
Adam
  • 1
  • 2
    *I'm trying to print ...*. If you just want to print it in that format, use a format statement. Don't round the number itself. `print("%.3g" % p_value)` – lurker May 22 '20 at 13:52

2 Answers2

1

When you use round you are changing the value and in your example rounding to the nearest thousandth. You only want to change the display format. "{:.2e}".format(4.3289045262877305e-11) will create a string with the representation you want. 4.33e-11

More details: https://kite.com/python/answers/how-to-print-a-number-in-scientific-notation-in-python

Derek S.
  • 348
  • 1
  • 7
-1

When using round(,3) you are rounding up the actual value to 0,00, not the displayed value. If you actually need to round the value itself and not the displayed one, I would suggest you to multiply it by e11, then round (,3), then devide it by e11 to get the rounded number.