Converting 5.223701009526849e-05 to 5e-05

Chris Angelico rosuav at gmail.com
Sun May 3 06:57:25 EDT 2015


On Sun, May 3, 2015 at 8:02 PM, Cecil Westerhof <Cecil at decebal.nl> wrote:
>>> If the absolute value is bigger as 0 and smaller as 1, it should be
>>> a float. ;-)
>>
>> Or maybe a fractions.Fraction, or a decimal.Decimal, or a complex,
>> or maybe a RXSTRING or a Gmp.mpf! There's more than one way to store
>> a number...
>
> Oops. :'-(
> I still have to learn a lot.

We all do :) Not all of those are Python types, incidentally. The
first three are, although 'complex' is a bit of a cheat (a complex
number is stored as two floats, so a complex with an imag of 0 is
virtually identical to a straight float); RXSTRING is the one and only
data type in REXX, and is (as the name suggests) stored as a string;
and Gmp.mpf is Pike's data type for a floating-point value stored
using the GNU Multiprecision library (gmp), and is thus capable of
arbitrary precision storage just like Python's own integer type. And
of course, the old fogeys among us know a bunch more ways to store
floating point values - not to mention all the ways of storing *fixed*
point values (the simplest being to just store an integer with the
number of hundredths of whatever it is you have - eg storing a dollar
amount as an integral number of cents). You'd be amazed how many
different ways there are of doing the same thing!

ChrisA



More information about the Python-list mailing list