1

Let's say I have a double precision value

a = 1.5838619160273860E-021

Is there a way to create a string b

b = '1.5838619160273860E-021'

Note the index has three digits here E-021 instead of E-21. I know format(int, '0.16f') can control the decimal place, but no idea how to manipulate the index.

Any input will be appreciated

SimonInNYC
  • 400
  • 3
  • 15

1 Answers1

0

You need another case for when its +21 instead of -21

>>> x = '1.5838619160273860E-21'
>>> a,b = x.split('E-')
>>> 'E-'.join((a,b.zfill(3)))
'1.5838619160273860E-021'
Rusty Rob
  • 16,489
  • 8
  • 100
  • 116