Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89680
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.028 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'string.': 0.05; 'binary': 0.07; 'float': 0.07; 'assumed': 0.09; 'formatting': 0.09; 'subject:number': 0.09; 'fine.': 0.16; 'nearest': 0.16; 'rounding': 0.16; 'size,': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'thu,': 0.19; 'solution.': 0.20; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'specify': 0.24; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'url:mailman': 0.30; '(which': 0.31; 'gives': 0.31; 'getting': 0.31; 'fine,': 0.31; 'probably': 0.32; 'worked': 0.33; 'url:python': 0.33; 'style': 0.33; "can't": 0.35; 'but': 0.35; 'there': 0.35; '+0200,': 0.36; 'url:listinfo': 0.36; "didn't": 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'represent': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'realize': 0.39; 'url:2012': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'read': 0.60; 'numbers': 0.61; 'range': 0.61; "you're": 0.61; 'further': 0.61; 'more': 0.64; '30,': 0.65; 'charset:windows-1252': 0.65; 'answer.': 0.68; 'received:74.208': 0.68; 'hoping': 0.75; '2015': 0.84; 'hundred': 0.95 |
| Date | Thu, 30 Apr 2015 18:58:50 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Rounding a number |
| References | <du05kahu2bla717q2b09fc2p0foou7odcd@4ax.com> <mailman.144.1430424020.3680.python-list@python.org> <7fb5kad577q6rug73bjmrguhuffhn28mlh@4ax.com> |
| In-Reply-To | <7fb5kad577q6rug73bjmrguhuffhn28mlh@4ax.com> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V03:K0:AQUjUU5tbX/vZpyxVnIdsvChvfYGeVTYXjNm6+80KAjVAxQMyQp mWglOXoW78+O9p9OWdHZJqjEc3uQozITRagN3ftLxjyCjMS5SQUkWn+NBufm7LF06YorWM5 mt8f3t2z/ksP6PYa4VS+83EDsVEAV1j0ygtA/xz9d7f/2ylnFzE+8m3LgY7TxZJPhPpF1ef W1PFb1G9wtKSEDSPdywBQ== |
| X-UI-Out-Filterresults | notjunk:1; |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.151.1430434742.3680.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430434742 news.xs4all.nl 2852 [2001:888:2000:d::a6]:47643 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89680 |
Show key headers only | View raw
On 04/30/2015 06:35 PM, Seymore4Head wrote:
> On Thu, 30 Apr 2015 22:00:17 +0200, Thijs Engels
> <thijs@buckazoids.com> wrote:
>
>> round(65253, -3)
>>
>> might be what you are looking for...
>>
>>
>> On Thu, Apr 30, 2015, at 21:49, Seymore4Head wrote:
>>> I have this page book marked.
>>> https://mkaz.com/2012/10/10/python-string-format/
>>>
>>> I am getting numbers from sixty thousand to two hundred thousand.
>>> I would like to round them to the nearest thousand.
>>> So 65,253 should read 65,000.
>>> How?
>>>
>>> Total=2100
>>> for x in range (10,35):
>>> count=1000/x
>>> print ("Foo {:7,.0f} Fighters".format(Total*count))
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
> Thanks
>
> I know there are more than one way to round and answer. I was hoping
> that using the {:7,.0f} formatting had a solution.
>
There are definite tradeoffs, but since you're rounding to integer size,
the round() function works fine. If you wanted tenths, you'd have to
realize that a float (which is binary float) can't represent them
exactly. So depending on what further processing you do, you might see
some effects that would not seem like it worked right.
Using the % or the .format style of formatting works fine, but it gives
you a string. You didn't specify that, so people probably assumed you
wanted numbers.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Rounding a number Seymore4Head <Seymore4Head@Hotmail.invalid> - 2015-04-30 15:49 -0400
Re: Rounding a number Thijs Engels <thijs@buckazoids.com> - 2015-04-30 22:00 +0200
Re: Rounding a number Seymore4Head <Seymore4Head@Hotmail.invalid> - 2015-04-30 18:35 -0400
Re: Rounding a number Dave Angel <davea@davea.name> - 2015-04-30 18:58 -0400
Re: Rounding a number Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-30 21:08 +0100
Re: Rounding a number Tony the Tiger <tony@tiger.invalid> - 2015-05-02 21:34 +0000
csiph-web