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


Groups > comp.lang.python > #42333

Re: round off to two decimal & return float

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!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.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'string.': 0.05; 'assign': 0.07; 'float': 0.07; 'subject:two': 0.07; 'string': 0.09; 'formatting': 0.09; 'imply': 0.09; 'thus,': 0.09; 'cc:addr:python- list': 0.11; 'assume': 0.14; '&gt;&gt;': 0.16; 'aligned.': 0.16; 'trying': 0.19; "python's": 0.19; '>>>': 0.22; 'preferred': 0.22; 'cc:addr:python.org': 0.22; 'print': 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; 'needed.': 0.30; '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; 'two': 0.37; 'from:addr:googlemail.com': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'url:mail': 0.40; 'course': 0.61; 'subject: & ': 0.68; 'default': 0.69; '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; '9.2': 0.91
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=WhgWlXVOmeK8MFkpNwv0po0+TiDmUgBKogQhw7tJYlU=; b=inKHIuUtbY/ooivTUbk+8rMLV2T8dJYegnxcoEyR3HyWkuSBUJVFNTQu9w7b4Sjuz+ LXqSYBjTRHp6oqSbTkAjsvRhVFpC1bu0zHwLwP1gEGfK6aeAn7+h9z6uvOSgMCz1imsV WHbNWXucN23S9Kp6TQ5eFeu3JaiOhqd2HtysH0v+6g0XJQgjGAWMVhG2D2ON+iRR10eO xX/QvW/vX1wJaYkcT1ydWI3Qlk+yTldNeIlg6ayG2OHX7HGQy5ynar5ri9GcLOxem3UC pPef/GPcejMI+PCuOH+kKBQ3hyUb7ohrWaylQ8GLDfcm0tMMZhfUVe6nlfyiQENR2HEY MPvg==
X-Received by 10.112.26.106 with SMTP id k10mr2656281lbg.5.1364636646941; Sat, 30 Mar 2013 02:44:06 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CALk2KRU37Ri-EfwGKZK3MR-MHBoCuvx1u6DDj7BqBcav+9OqCA@mail.gmail.com>
References <515699DB.8060104@amachu.me> <CALk2KRU37Ri-EfwGKZK3MR-MHBoCuvx1u6DDj7BqBcav+9OqCA@mail.gmail.com>
From Roland Mueller <roland.em0001@googlemail.com>
Date Sat, 30 Mar 2013 11:43:46 +0200
Subject Re: round off to two decimal & return float
To ஆமாச்சு <amachu@amachu.me>
Content-Type multipart/alternative; boundary=bcaec554dbbe96add504d9213ab8
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.3995.1364636655.2939.python-list@python.org> (permalink)
Lines 156
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364636655 news.xs4all.nl 6969 [2001:888:2000:d::a6]:56765
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42333

Show key headers only | View raw


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

2013/3/30 Roland Mueller <roland.em0001@googlemail.com>

> 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():
>
> Of course the representation of the float having a given number of
 decimals printed out is always a string. The float format does not imply
any formatting and Python's default formatting when a float is printed out
is to print as decimals as needed. Thus, using round() fives you a float
with maximal two decimals.

>>> a = 9.2022222
>>> a = round(a,2)
>>> a
9.2

>>> a = 9.2222222
>>> a = round(a,2)
>>> a
9.22


>>> 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:43 +0200

csiph-web