RE: Floating point -> string conversions

From: Andrew A. Cox (Andrew_at_ferndale.net.nz)
Date: 11/21/04


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


Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)

Loading