Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89666 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2015-04-30 15:49 -0400 |
| Last post | 2015-05-02 21:34 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2015-04-30 15:49 -0400 |
| Subject | Rounding a number |
| Message-ID | <du05kahu2bla717q2b09fc2p0foou7odcd@4ax.com> |
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))
[toc] | [next] | [standalone]
| From | Thijs Engels <thijs@buckazoids.com> |
|---|---|
| Date | 2015-04-30 22:00 +0200 |
| Message-ID | <mailman.144.1430424020.3680.python-list@python.org> |
| In reply to | #89666 |
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
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2015-04-30 18:35 -0400 |
| Message-ID | <7fb5kad577q6rug73bjmrguhuffhn28mlh@4ax.com> |
| In reply to | #89667 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2015-04-30 18:58 -0400 |
| Message-ID | <mailman.151.1430434742.3680.python-list@python.org> |
| In reply to | #89678 |
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
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-04-30 21:08 +0100 |
| Message-ID | <mailman.145.1430424529.3680.python-list@python.org> |
| In reply to | #89666 |
On 30/04/2015 21:00, Thijs Engels wrote:
> 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
> round(65253, -3)
>
> might be what you are looking for...
>
>
True, but please don't top post here. It's no problem on short threads,
but as they get longer trying to follow when top posting is involved is
nigh on impossible.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Tony the Tiger <tony@tiger.invalid> |
|---|---|
| Date | 2015-05-02 21:34 +0000 |
| Message-ID | <Tpb1x.386615$JH2.380066@fx11.am4> |
| In reply to | #89666 |
On Thu, 30 Apr 2015 15:49:52 -0400, 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?
One solution, not necessarily the best:
>>> int(round(65253/1000, 0)*1000)
65000
/Grrr
--
___ ___
(\_--_/) | _ ._ _|_|_ _ |o _ _ ._
( 9 9 ) |(_)| |\/ |_| |(/_ ||(_|(/_|
stripes are forever - as overripe ferrets
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web