Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:verizon.net': 0.07; 'terry': 0.07; 'assumed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'output': 0.11; 'am,': 0.13; 'float': 0.13; 'wrote:': 0.15; 'goal.': 0.16; 'literals': 0.16; 'reedy': 0.16; 'subject:Convert': 0.16; 'value"': 0.16; "subject:' ": 0.16; 'int': 0.19; 'jan': 0.19; 'appropriate': 0.20; 'header :In-Reply-To:1': 0.22; 'works.': 0.23; 'specify': 0.25; 'function': 0.26; 'sort': 0.28; 'problem': 0.29; 'not.': 0.30; 'value.': 0.32; 'does': 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'but,': 0.34; 'nobody': 0.34; 'post': 0.34; 'example,': 0.35; 'that,': 0.35; 'integer': 0.35; 'response': 0.37; 'some': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'two': 0.38; 'perhaps': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'did': 0.40; 'dans': 0.77; '11:47': 0.84; '??????.': 0.84; 'jay': 0.84; 'edwards': 0.91; 'leo': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Convert '165.0' to int Date: Thu, 21 Jul 2011 16:00:28 -0400 References: <4e281f97$0$16404$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311278441 news.xs4all.nl 23881 [2001:888:2000:d::a6]:45338 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10045 On 7/21/2011 10:13 AM, Grant Edwards wrote: > On 2011-07-21, Web Dreamer wrote: >> Leo Jay a ?crit ce jeudi 21 juillet 2011 11:47 dans > >> int(x.split('.')[0]) >> >> But, the problem is the same as with int(float(x)), the integer number is >> still not as close as possible as the original float value. > > Nobody said that "close as possible to the original float value" was > the goal. Perhaps the OP just wants it truncated. The OP did not specify the domain of possible inputs nor the desired output for all possible inputs. Without that, function design is guessing. The appropriate response to the original post would have been a request for clarification. If the domain is strings with and int followed by '.0', then chopping off two chars is sufficient. This was sort of implied by the original post, since it was the only example, and assumed by the respondant. If the domain is int literals followed by '.' and some number of zeroes, then split works. So does int(float(s)). Split also works for non-digits following '.' whereas int(float(s)) does not. If the domain is all float literals, then ??????. -- Terry Jan Reedy