I want to display the value 6.1234567891e-05 as 6.123e-05 using python I tried using function round(). But its giving me wrong answer. Please help me with a solution.
Regards, Sneha
I want to display the value 6.1234567891e-05 as 6.123e-05 using python I tried using function round(). But its giving me wrong answer. Please help me with a solution.
Regards, Sneha
You need to use string formatting.
n = 6.1234567891e-05
print '%1.3e'%n
Take a look at this for a quick reference: https://mail.python.org/pipermail/tutor/2008-June/062649.html
You can set the number of decimals to print without changing the model of the data but just changing the view. For example if you want only three numbers after the dot you can use:
'%.3e' % n
>>> print '%.3e' % 0.000061234567891
6.123e-05