RE: Floating point -> string conversions
From: Andrew A. Cox (Andrew_at_ferndale.net.nz)
Date: 11/21/04
- Next message: Steve Holden: "Re: CGI email script"
- Previous message: Steve Holden: "Re: generic object - moving toward PEP"
- Maybe in reply to: John Fouhy: "Floating point -> string conversions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Nov 2004 09:20:08 +1300 To: <python-list@python.org>
I disagree with '%d' you have explicitly requested that the number be
turned into an integer for use as a string, so you expect that as long
as you feed it a number (be it int, long or float) that it changes to a
string representation of an integer. Now it may be nice to have a flag
that says how you want to round it.
-----Original Message-----
From: John Fouhy [mailto:jfouhy@paradise.net.nz]
Sent: Friday, 19 November 2004 2:47 p.m.
To: python-list@python.org
Subject: Re: Floating point -> string conversions
Steve Holden <steve@holdenweb.com> wrote in message
news:<t9Skd.57$nj.56@lakeread01>...
> The fact that %s coerces things makes us expect more of other format
> tokens, but what would you expect %d to do with 2147483648.5?
I'd expect it to give me "2147483648", since that would be consistent
with its other behaviour :-)
(eg: eval('"%d" % 1.5') == '1')
I guess what annoys me is that python encourages you to not worry
about the difference between ints and longs (which is great) (unless
you're doing high performance computing), but then something like this
can cause code to stop working just because you've passed a border
which is almost invisible.
(of course, this means that one solution which I would be happy with
is for python to reject any non-integer/long arguments to "%d" :-) )
-- John. -- http://mail.python.org/mailman/listinfo/python-list
- Next message: Steve Holden: "Re: CGI email script"
- Previous message: Steve Holden: "Re: generic object - moving toward PEP"
- Maybe in reply to: John Fouhy: "Floating point -> string conversions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|