Dustan <DustanGroups@g mail.com> wrote:
[color=blue]
> How can I get a number into scientific notation? I have a preference
> for the format '1 E 50' (as an example), but if it's well known, it
> works.[/color]
You mean something like:
[color=blue][color=green][color=darkred]
>>> print '%e' % (1e50)[/color][/color][/color]
1.000000e+50
Exactly: the "%e" builds a ``scientific-notation" string from whatever
number you're formatting that way (big or small). You can also use %g
if what you want is fixed-point notation within a certain range and
scientific notations only for numbers OUTSIDE that range, as in:
[color=blue][color=green][color=darkred]
>>> print '%g' % 10**5[/color][/color][/color]
100000[color=blue][color=green][color=darkred]
>>> print '%g' % 10**50[/color][/color][/color]
1e+50
"Dustan" <DustanGroups@g mail.com> writes:
[color=blue]
> No, I mean given a big number, such as
> 100000000000000 000000000000000 000000000000000 0000000, convert it into
> scientific notation.[/color]
> > > You mean something like:[color=blue][color=green][color=darkred]
> > >
> > > >>> print '%e' % (1e50)
> > > 1.000000e+50
> > >
> > > ...?[/color][/color]
>[color=green]
> > No, I mean given a big number, such as
> > 100000000000000 000000000000000 000000000000000 0000000, convert it into
> > scientific notation.[/color]
>
> It's the same.
>[color=green][color=darkred]
> >>> print "%e" % 100000000000000 000000000000000 000000000000000 0000000[/color][/color]
> 1.000000e+51[/color]
one would have assumed that someone who *prefers* to use scientific notation
for large numbers would in fact know that, but the usenet never ceases to sur-
prise me...
Comment