# cat num.py
#!/usr/bin/env python
from decimal import Decimal
def main():
numbers = '''1.757E-4
7.51E-3
5.634E-5'''
numbers= [num.strip() for num in numbers.split('\n')]
for num in numbers:
print "scientific: %s decimal: %s" % (num,str(Decimal(num)))
if __name__=="__main__":
main()
The output result is different from what I expected.
Apart from that, is it possible your command work for something like "1.757E-100" and return "7.51E-3" as "0.00751" instead of "0.00751000".
Really thanks and sorry for troubling you.
---------- Post updated at 09:04 AM ---------- Previous update was at 08:57 AM ----------
Hi Klashxx,
I just try your python script with the data set.
But it return the following error message:
File "./num.py", line 9
except Exception,err:
^
IndentationError: unexpected indent
Is there something wrong with my python program?
Thanks for advice.
What you show there is the "%.8g" behaviour. It will not fill the field length with 0 as "%f" does, but it will resort to e- notation if the exponent ist less than -4. I'm afraid that can't be modified; you may need to do string manipulations, then. Or use sth. like python etc..
Really many thanks and appreciate your advice.
I guess you're right.
It will resort to e- notation if the exponent ist less than -4.
In that case, I will try to see whether python or any other way to solve my doubts.
Really appreciate your assist.
Thanks again.