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


Groups > comp.lang.python > #42328

Re: round off to two decimal & return float

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <roland.em0001@googlemail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'assign': 0.07; 'float': 0.07; 'subject:two': 0.07; 'string': 0.09; 'cc:addr:python-list': 0.11; 'assume': 0.14; '&gt;&gt;': 0.16; 'aligned.': 0.16; 'trying': 0.19; '>>>': 0.22; 'preferred': 0.22; 'cc:addr:python.org': 0.22; '&gt;&gt;&gt;': 0.24; '(a)': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'text': 0.33; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'from:addr:googlemail.com': 0.38; 'skip:& 20': 0.39; 'url:mail': 0.40; 'subject: & ': 0.68; '8bit%:100': 0.72; '\xc2\xa0\xc2\xa0': 0.74; 'br,': 0.84; 'skip:\xe0 20': 0.84; 'sri': 0.84; 'subject:round': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=a9CgeISnk0iwAO0QwokcvsEO28RiBXQXWdbOFLGdhPs=; b=d4lhaBr3bWJRjDj2bzU6476KNEPRFDHdK9B3Z77SQnMI+iE8NFw06XFKlgRzVhfIX9 JH0vRLmWyUUshtC+ZNlO6qgXaC33cL1YyFlNhTOoZa1EcJXufn19ShQJUxvL4UBopV4L BrK3dMtGRh5Tbxx2eavwGt8cymfAT+EcBlt4O5zUVx1/opRMGF+OWH2wVYsSBnbIHZ5F /ieYYrdC3E7gNmxYdyrtuEuR1+0CipTc83Dxs7USwLcnYPtaCwmADz1qWYiqgS5UPR7T f2Dp2nRyUeinpFyRif6mdYNDFJdlUrGZHTQpTPtTrvZx3h+bo91wCSUHfj2r4P6AXhkf xLWA==
X-Received by 10.112.143.129 with SMTP id se1mr2546380lbb.120.1364635741709; Sat, 30 Mar 2013 02:29:01 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <515699DB.8060104@amachu.me>
References <515699DB.8060104@amachu.me>
From Roland Mueller <roland.em0001@googlemail.com>
Date Sat, 30 Mar 2013 11:28:41 +0200
Subject Re: round off to two decimal & return float
To ஆமாச்சு <amachu@amachu.me>
Content-Type multipart/alternative; boundary=089e0116070ea1eb6904d9210416
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>
Newsgroups comp.lang.python
Message-ID <mailman.3991.1364635750.2939.python-list@python.org> (permalink)
Lines 114
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364635750 news.xs4all.nl 6865 [2001:888:2000:d::a6]:46862
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42328

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hello,

2013/3/30 ஆமாச்சு <amachu@amachu.me>

> Consider the scenario,
>
> >> a = 10
> >> "{0:.2f}".format(a)
> '10.00'
>
> This returns a string 10.00. But what is the preferred method to retain
> 10.0 (float) as 10.00 (float)?
>
> I assume you have a numeric value a and want to have a float with 2
decimals. This can be achieved with the function round():

>>> a = 10


>>> type(a)
<type 'int'>

>>> a = round(10,2)



>>> type (a)


<type 'float'>


>>> a


10.0

BR,
Roland


> I am trying to assign the value to a cell of a spreadsheet, using
> python-xlwt. I would like to have 10.00 as the value that is right
> aligned. With text it is left aligned.
>
> --
>
> Sri Ramadoss M
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Re: round off to two decimal & return float Roland Mueller <roland.em0001@googlemail.com> - 2013-03-30 11:28 +0200

csiph-web