Decimal() instead of float?

John Machin sjmachin at lexicon.net
Sun Nov 12 04:14:13 EST 2006


Steven D'Aprano wrote:
> On Sun, 12 Nov 2006 02:31:04 +0100, Fredrik Lundh wrote:
>
> >> For example, I have a ZIP code
> >> database that can do some processing on its numbers, and the numbers are
> >> stored as floating point values (exactly) but Python doesn't get them
> >> right
> >
> > sounds odd.  are you sure you don't mean "stored as strings containing
> > decimal numbers" ?
> >
> > (who uses fractional ZIP codes, btw?)
>
> Well, I can't speak for Americans, but here in Australia we typically give
> our post codes to six decimal places:
>
> Melbourne 3000.000000
> Brunswick 3056.000000
> Clifton Hill 3068.000000
> Sydney 2000.000000
> St Johns Park 2176.000000
>
> and so forth. You can't have too much precision with those floating point
> post/ZIP codes!

Here in Austraila, (I expect this is common to most countries), there
are people who are utterly clueless about elementary data model rules,
like identification "numbers" should be kept as strings.

E.g. (1) National grief started over twenty years ago when the Post
Office started using postcodes with leading zeroes, and continues to
the present. The postcode for Darwin can be stored as 800, "800", or
"0800".

E.g. (2) Many Australians have a Tax File Number (TFN) which is a
9-digit number with an "officially kept secret" check digit algorithm
(you need to sign an NDA with the Tax Office). Storing this as an
integer allows the TFN be negative -- if the data entry for say
123456789 is actually 123456789-, you don't check for anything (length,
allowable characters, check digit) and an old-fashioned
trailing-minus-allowed conversion-to-integer routine is used.

Cheers,
John




More information about the Python-list mailing list