Round a decimal number
Peter Hansen
peter at engcorp.com
Fri May 30 07:29:04 EDT 2003
Manuel wrote:
>
> > If you want to round the number itself, it might be a good idea to
> > post here why you do, in case it's not a good idea and there are
> > better ways to do it (eg, in financial applications).
>
> Thanks to all.
> :-)
>
> I'm writing a simple exporter of 3D file format.
> In some cases, in the generated file, I've a numbers like
>
> 8.70421814625e-008
>
> The problem is that the "e-008" can't be used
> in the client 3d software. I must round it??
Does this help?
>>> f = 8.70421814625e-008
>>> f
8.7042181462500001e-008
>>> print f
8.70421814625e-008
>>> print '%f' % f
0.000000
>>> print '%g' % f
8.70422e-008
Check the documentation for the % formatting operator to learn more.
-Peter
More information about the Python-list
mailing list