You can write your own format function based on scientific notation.
def format(num,kk,cc=12):
fmt = '{0:.'+str(kk+cc-1)+'e}'
ss = fmt.format(num);
s1 = ss.replace('.','')
p1 = s1.split('e')
a1 = p1[0]
a2 = int(p1[1])
return '{0}.{1}e{2}'.format(a1[0:kk],a1[kk:],a2-kk+1)
For convenience, you can create an object with a custom format:
class MyNum:
def __init__(self,value):
self.value = value
def __format__(self,fmt):
args = fmt.split('.')
a1 = int(args[0]) if len(args) > 0 else 1
a2 = int(args[1]) if len(args) > 1 else 6
return format(self.value,a1,a2)
:
print('{0:3.6}'.format(MyNum(25.123456789)))