Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42331

Re: round off to two decimal & return float

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <julius.welby@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.026
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'float': 0.07; 'subject:two': 0.07; 'output,': 0.09; 'separately': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'folder.': 0.16; 'notation,': 0.16; 'unchanged': 0.16; 'module': 0.19; 'options.': 0.19; 'not,': 0.20; '(the': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'module,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'define': 0.26; 'excel': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'leave': 0.29; 'generally': 0.29; 'converting': 0.30; 'specified': 0.30; "i'm": 0.30; 'easier': 0.31; 'decimal': 0.31; 'allows': 0.31; 'open': 0.33; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'shows': 0.36; 'should': 0.36; 'example,': 0.37; 'two': 0.37; 'received:209': 0.37; 'handle': 0.38; 'skip:p 20': 0.39; 'how': 0.40; 'tell': 0.60; 'you.': 0.62; 'kind': 0.63; 'skip:n 10': 0.64; 'places': 0.64; 'different': 0.65; 'date,': 0.68; 'frequently': 0.68; 'subject: & ': 0.68; 'default': 0.69; 'confusing': 0.84; 'excel.': 0.84; 'percentage,': 0.84; 'subject:round': 0.84
X-Received by 10.49.41.65 with SMTP id d1mr349654qel.11.1364635809039; Sat, 30 Mar 2013 02:30:09 -0700 (PDT)
Newsgroups comp.lang.python
Date Sat, 30 Mar 2013 02:30:08 -0700 (PDT)
In-Reply-To <mailman.3990.1364630137.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=86.169.72.71; posting-account=heV9gAoAAAAKKGco1KI1AfzmwEpibkv0
References <mailman.3990.1364630137.2939.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 86.169.72.71
MIME-Version 1.0
Subject Re: round off to two decimal & return float
From pyplexed <julius.welby@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.3993.1364636590.2939.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364636590 news.xs4all.nl 6840 [2001:888:2000:d::a6]:56023
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42331

Show key headers only | View raw


Hi Sri.

I'm not familiar with the xlwt module, but I think you are confusing two different things here.

Generally spreadsheets separate out how they handle the value in a cell (the value) and how that value is displayed (the format). This means that the you leave the cell value unchanged when you tell Excel separately that the number should be displayed as, for example, a percentage, a date, in scientific notation, or as a float with a specified number of decimal places etc.

Try converting the integer to a floating point number using float(a), and see what the default format for floats looks like when you open the output in Excel. It may be OK for you. If not, take a look at the python-xlwt/examples folder. num_formats.py shows how to apply Excel number formats to cells.

By the way, if you are doing this kind of thing frequently or at any kind of scale, you may find it easier to use something like the pandas module to do your data manipulation and then you can use pandas' DataFrame.to_excel method which allows you to define a format for floats in the output, and also provides many other options.

HTH

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

round off to two decimal & return float ஆமாச்சு <amachu@amachu.me> - 2013-03-30 13:22 +0530
  Re: round off to two decimal & return float pyplexed <julius.welby@gmail.com> - 2013-03-30 02:30 -0700
  Re: round off to two decimal & return float pyplexed <julius.welby@gmail.com> - 2013-03-30 02:30 -0700

csiph-web