Mario Vago Marzal
Mario Vago Marzal

Reputation: 19

Print personalized scientific notation in Python

The question is simple: If I have a number x = 2.8e-11 and I want to print it in this format: 2.8 · 10^(-11), what should I do?

Thank you in advance.

Upvotes: 0

Views: 74

Answers (1)

BlivetWidget
BlivetWidget

Reputation: 11063

I would just do this with string operations.

>>> x = 2.8e-11
>>> if 'e' in str(x):
    print(str(x).replace('e', ' · 10^(') + ')')

    
2.8 · 10^(-11)

Upvotes: 1

Related Questions