-1

I want to output the result of a power operation, for example:

100**100

However instead of outputting:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

I want it to output a result which includes "e" in it:

1e+200

I have looked on other similar Stack Overflow questions, but I couldn't find a way for me to do this without defining another function for this.

Is there an inbuilt Python function to do this?

topsoftwarepro
  • 773
  • 5
  • 19
  • Thank you for the suggestion, it is my mistake for not adding more detail in my question. I have done so now, but I was looking for a way to do this without having to define a new function to do this. – topsoftwarepro Jan 15 '21 at 05:32
  • 3
    The `e` in scientific notation refers to exponent, not Euler's Number which is e = 2.7182818284590452353602874713527........ – mhawke Jan 15 '21 at 05:34
  • Thank you I have fixed that in my question. – topsoftwarepro Jan 15 '21 at 05:38

2 Answers2

4

If its just about printing then use this -

e = 100**100
"{:.2e}".format(e)
'1.00e+200'
Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51
3

use str.format() to print a number in scientific notation, use "{:e}" as str to format the number in scientific notation.

number = 12300000
value = "{:.2e}".format(number)

print(value)

output : 1.23e+07

Sahadat Hossain
  • 3,583
  • 2
  • 12
  • 19