strings (dollar.cents) into floats

John Machin sjmachin at lexicon.net
Fri Aug 31 17:51:50 EDT 2007


On Sep 1, 4:51 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Fri, 31 Aug 2007 12:06:49 -0400, Steve Holden <st... at holdenweb.com>
> declaimed the following in comp.lang.python:
>
> > That last sentence is patent nonsense, and completely untrue. Many
> > satisfactory financial applications have been written using only
> > floating-point arithmetic. Indeed I believe the accountant's Swiss army
> > knife, the Excel spreadsheet, uses floating-point numbers exclusively.
>
>         Excel supports M$'s "Currency" data type

That sentence is also completely untrue. Excel supports only IEEE 754
64-bit floating point, and that is how bean-counts, temperature
readings, dates, and money amounts are stored in an XLS file. What is
confusing you may be the "helpful" way that COM etc examine the
"number format" that's been used on a cell.

Example: actual value is 1.234567..... (a float). The "number format"
used in Excel causes it to be displayed as $1.23. However what COM etc
produce when they extract the data is a "currency" or "money" instance
containing $1.2345 which is NEITHER what you see NOR what you've
actually got. That's a somewhat Procrustean attitude to "support".

> -- which I believe is a
> 64-bit INTEGER scaled for four decimal places.
>
>         It's "general" format is a variant type accepting integer, float,
> text, date/time (but can't differentiate currency form float on input)

Excel has no concept of a variant type. "General" is a "number
format", not a data type. Excel has storage types corresponding to
Python's float, unicode (16 bit), bool and None, as well as an error
type.





More information about the Python-list mailing list