Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: Curious Omission In New-Style Formats Date: Wed, 13 Jul 2016 07:46:42 -0400 Organization: IISS Elusive Unicorn Lines: 21 Message-ID: References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de Un/QGZolqNzgQfGIXKMrAwjMMmCQVpU2Xbeq3iDHuF6A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; 'integer,': 0.09; 'integers': 0.09; 'message-id:@4ax.com': 0.09; 'output?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'toss': 0.09; 'wed,': 0.15; '"."': 0.16; '2016': 0.16; 'fixed-point': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'integer': 0.18; 'url:home': 0.18; 'math': 0.20; 'accuracy': 0.23; 'insert': 0.23; 'split': 0.23; "i've": 0.25; 'header:X-Complaints- To:1': 0.26; 'converting': 0.27; 'operations,': 0.27; 'decimal': 0.29; 'window': 0.30; "skip:' 20": 0.34; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset:us- ascii': 0.37; 'doing': 0.38; 'format': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'jul': 0.72; 'dennis': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-79-216-14.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:111388 On Wed, 13 Jul 2016 00:21:17 -0600, Ian Kelly declaimed the following: >What if I've been doing my math with fixed-point integers (because I >don't know about or just don't like decimals), and now I want to >format them for output? Is this just wrong? > > '{:.2f}'.format(int_value / 100) > Ugh... After using integers to keep accuracy in the LSB, you know toss it out the window by converting to a float which may have an inexact representation. Presuming you kept track of the decimal place during all those integer operations, format as an integer, then split it at the decimal and insert a "." at the spot. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/