Numeric data question
James J. Besemer
jb at cascade-sys.com
Wed Jul 24 16:43:12 EDT 2002
Chris Barker wrote:
> Do any programming languages have a built in "money" type?
Visual Basic does, as I am sure do several others. Curency was not part of VB for
quite a while. I believe currency eventually was introduced to VB mainly in order
to facilitate interfacing with various database engines, most all of which have an
explicit currency type (distinct from real and int).
The Python interfaces to MySql and MSql implement a currency type for this very
reason. Time and Date also. These in fact are not arbitrary implementations of
currency, et al., but necessarily track the database native format and ease
conversion to/from native Python formats.
Amongst the various attributes that may be counted on the list of benefits of an
explicit currency type are (a) it is a good place to isolate locale issues and (b)
accuracy requirements generally prohibit use of floating point (which is
intrinsically inaccurate for decimal fractions) or integers (which lack the
necessary precision).
Of course, such a thing could be implemented in Python as you suggest, probably
with longs or strings emulating fixed-point numbers.
All those cute anecdotes about round off error -- they're not actually tolerated
in real commerce applications.
Regards
--jb
--
James J. Besemer 503-280-0838 voice
http://cascade-sys.com 503-280-0375 fax
mailto:jb at cascade-sys.com
More information about the Python-list
mailing list