On 04/30/2015 06:35 PM, Seymore4Head wrote:
On Thu, 30 Apr 2015 22:00:17 +0200, Thijs Engels
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 a
On Thu, 30 Apr 2015 22:00:17 +0200, Thijs Engels
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 t
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 6
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
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 ("
On Apr 13, 7:20 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Lie wrote:
> > On Apr 12, 3:44 am, hdante <[EMAIL PROTECTED]> wrote:
> [snip]
>
> > In short, choosing that x.0 is rounded down and x.5 is rounded up is
> > arbitrary but not without a reason.
>
> Don't "arbitrary" and "not without a rea
On 11 Apr, 21:29, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> ... If the numbers to be rounded come from a
> measurement, the left column is not just a number but the representant
> of an interval (as Mikael said, the're quantized). 2.3 means that the
> measurement was closer to 2.3 than to 2.2
On Apr 15, 12:33 pm, Chris <[EMAIL PROTECTED]> wrote:
> On Apr 15, 11:47 am, Duncan Booth <[EMAIL PROTECTED]>
> wrote:
>
> > Chris <[EMAIL PROTECTED]> wrote:
> > > even is closer to even.75 than even+1.25. Why should it be rounded
> > > up ?
>
> > Because the OP wants to round values to the neares
On Apr 15, 11:47 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> Chris <[EMAIL PROTECTED]> wrote:
> > even is closer to even.75 than even+1.25. Why should it be rounded
> > up ?
>
> Because the OP wants to round values to the nearest integer. Only values of
> the form 'x.5' which have two nearest va
Chris <[EMAIL PROTECTED]> wrote:
> even is closer to even.75 than even+1.25. Why should it be rounded
> up ?
Because the OP wants to round values to the nearest integer. Only values of
the form 'x.5' which have two nearest values use 'nearest even' to
disambiguate the result.
See http://en.wi
On 14 avr, 20:02, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote:
> On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote:
> > The built-in function round( ) will always "round up", that is 1.5 is
> > rounded to 2.0 and 2.5 is rounded to 3.0.
>
> > If I want to round to the nearest even, that is
>
> > m
On Apr 15, 11:22 am, Sjoerd Mullender <[EMAIL PROTECTED]> wrote:
> Thomas Dybdahl Ahle wrote:
> > On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote:
> >> The built-in function round( ) will always "round up", that is 1.5 is
> >> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> >> If I want to round to
Thomas Dybdahl Ahle wrote:
> On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote:
>> The built-in function round( ) will always "round up", that is 1.5 is
>> rounded to 2.0 and 2.5 is rounded to 3.0.
>>
>> If I want to round to the nearest even, that is
>>
>> my_round(1.5) = 2# As expected
>>
On Fri, 2008-04-11 at 03:14 -0700, bdsatish wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not 3,
On Apr 11, 4:14 am, bdsatish <[EMAIL PROTECTED]> wrote:
> I'm interested in rounding numbers of the form "x.5" depending upon
> whether x is odd or even. Any idea about how to implement it ?
Side note: A specialized use for this is in the US Field Artillery,
where it's called "artillery expressio
On Apr 13, 4:18 am, Lie <[EMAIL PROTECTED]> wrote:
[...]
> it and there is nothing else in it, but in the second number range
> (barely above 1 to 2) the number 1.0 is not included while the number
> 2.0 is contained in it, clearly not a clean separation of numbers in
> the form of y.x where y is p
Lie wrote:
> On Apr 12, 3:44 am, hdante <[EMAIL PROTECTED]> wrote:
[snip]
>
> In short, choosing that x.0 is rounded down and x.5 is rounded up is
> arbitrary but not without a reason.
Don't "arbitrary" and "not without a reason" directly contradict one
another?
regards
Steve
--
Steve Holden
On Apr 12, 3:44 am, hdante <[EMAIL PROTECTED]> wrote:
(snip)
> > In this table, we consider that a number is rounded down when the
>
> But then, the "Round up" table gives inconsistent results if, by the
> same argument, we consider 2.0 -> 2 rounding up. (you get 12 round ups
> and 8 round downs j
On Apr 11, 8:27 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Apr 11, 2:33 pm, Lie <[EMAIL PROTECTED]> wrote:
[...]
> > Another mistake, in an unquantized value the probability of getting
> > exactly 0.5 (or any other number specified) is not 0 but an
> > infinitesimal (i.e. lim(x) where x ->
On Apr 11, 3:33 pm, Lie <[EMAIL PROTECTED]> wrote:
>
> That old-school rounding method you're taught is based on a wrong
> assumption of the nature of number. In the past, rounding algorithm is
> based on this:
>
> Original => (RoundUp(u|d|n), RoundNearestEven(u|d|n)
> ...
> 1.0 => 1(n), 1(n)
> 1.1
On 11 abr, 15:33, Lie <[EMAIL PROTECTED]> wrote:
> On Apr 11, 10:19 pm, Mikael Olofsson <[EMAIL PROTECTED]> wrote:
> > That's exactly how I was taught to do rounding in what-ever low-level
> > class it was. The idea is to avoid a bias, which assumes that the
> > original values are already quantiz
On Apr 11, 2:33 pm, Lie <[EMAIL PROTECTED]> wrote:
> In this table, we consider that a number is rounded down when the
> number is equal to truncated value (the number without fractional
> part), while round up is equal to truncated value + 1 or truncated
> value -1 if value is negative (Actually t
On Apr 11, 10:19 pm, Mikael Olofsson <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] commented about rounding towards even numbers
> from mid-way between integers as opposed to for instance always rounding
> up in those cases:
>
> > Strange request though, why do you need it that way, because 2.5 is
On Apr 11, 10:29 am, hdante <[EMAIL PROTECTED]> wrote:
> Strangely, a "faster" version is:
>
> def fast_round(x):
> if x % 1 != 0.5: return round(x)
> return 2.0*round(x/2.0)
You should be a little bit careful with the test
x%1 == 0.5 if x might be negative:
>>> x = -0.5 + 2**-54
>>> x
[EMAIL PROTECTED] wrote:
> Strange request though, why do you need it that way, because 2.5 is
> CLOSER to 3 than to 2...
Uhhh, no it isn't. (3 - 2.5) == (2.5 - 2)
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad
[EMAIL PROTECTED] commented about rounding towards even numbers
from mid-way between integers as opposed to for instance always rounding
up in those cases:
> Strange request though, why do you need it that way, because 2.5 is
> CLOSER to 3 than to 2...
That's exactly how I was taught to do roundi
On Apr 11, 6:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not
On Apr 11, 11:13 am, Ivan Illarionov <[EMAIL PROTECTED]>
wrote:
>
> Shorter version:
> def round3k(x):
> return x % 1 != 0.5 and round(x) or round(x / 2.) * 2.
Strangely, a "faster" version is:
def fast_round(x):
if x % 1 != 0.5: return round(x)
return 2.0*round(x/2.0)
>
> nums =
On Apr 11, 5:49 pm, hdante <[EMAIL PROTECTED]> wrote:
> On Apr 11, 9:45 am, bdsatish <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Apr 11, 5:33 pm, bdsatish <[EMAIL PROTECTED]> wrote:
>
> > > HI Gerard,
>
> > > I think you've taken it to the best possible implementation. Thanks !
> > > On Apr 11, 5:14 pm
On Apr 11, 9:45 am, bdsatish <[EMAIL PROTECTED]> wrote:
> On Apr 11, 5:33 pm, bdsatish <[EMAIL PROTECTED]> wrote:
>
>
>
> > HI Gerard,
>
> > I think you've taken it to the best possible implementation. Thanks !
> > On Apr 11, 5:14 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
>
> > > In fact you c
On Apr 11, 2:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not
On Apr 11, 5:33 pm, bdsatish <[EMAIL PROTECTED]> wrote:
> HI Gerard,
>
> I think you've taken it to the best possible implementation. Thanks !
> On Apr 11, 5:14 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
>
> > In fact you can avoid the call to the builtin round:
>
> > --
On 11 avr, 14:14, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> On Apr 11, 2:05 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
>
> > On Apr 11, 12:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
>
> > > The built-in function round( ) will always "round up", that is 1.5 is
> > > rounded to 2.0 and 2.5 is
HI Gerard,
I think you've taken it to the best possible implementation. Thanks !
On Apr 11, 5:14 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> In fact you can avoid the call to the builtin round:
>
>
> def myround(x):
> n = int(x)
> if ab
On Apr 11, 2:05 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> On Apr 11, 12:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
>
> > The built-in function round( ) will always "round up", that is 1.5 is
> > rounded to 2.0 and 2.5 is rounded to 3.0.
>
> > If I want to round to the nearest even, that is
>
On Apr 11, 12:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# No
On Apr 11, 4:37 pm, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> bdsatish wrote:
> > The built-in function round( ) will always "round up", that is 1.5 is
> def rounded(v):
> rounded = round(v)
> if divmod(v, 1)[1] == .5 and divmod(rounded, 2)[1] == 1:
> if v > 0:
>
On Apr 11, 4:24 pm, [EMAIL PROTECTED] wrote:
> On Apr 11, 1:19 pm, [EMAIL PROTECTED] wrote:
>
> > couldn't you just do.
>
> > #untested
> > new_round(n):
> > answer = round(n)
> > # is answer now odd
> > if answer % 2:
> > return answer - 1
> > else:
> > return answer
>
> Whoops, th
bdsatish wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not 3, which is an odd num
>
> I'm inter
On Apr 11, 4:19 pm, [EMAIL PROTECTED] wrote:
> couldn't you just do.
>
> #untested
> new_round(n):
> answer = round(n)
> # is answer now odd
> if answer % 2:
> return answer - 1
> else:
> return answer
It fails for negative numbers: For -2.5 it gives -4.0 as answer
whereas I expect
On Apr 11, 1:19 pm, [EMAIL PROTECTED] wrote:
> couldn't you just do.
>
> #untested
> new_round(n):
> answer = round(n)
> # is answer now odd
> if answer % 2:
> return answer - 1
> else:
> return answer
Whoops, this also affects odd numbers...
Will try and find a GOOD solution late
couldn't you just do.
#untested
new_round(n):
answer = round(n)
# is answer now odd
if answer % 2:
return answer - 1
else:
return answer
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 11, 3:27 pm, [EMAIL PROTECTED] wrote:
> On 11 avr, 12:14, bdsatish <[EMAIL PROTECTED]> wrote:
>
> > The built-in function round( ) will always "round up", that is 1.5 is
> > rounded to 2.0 and 2.5 is rounded to 3.0.
>
> > If I want to round to the nearest even, that is
>
> > my_round(1.5) =
On 11 avr, 12:14, bdsatish <[EMAIL PROTECTED]> wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not 3
The built-in function round( ) will always "round up", that is 1.5 is
rounded to 2.0 and 2.5 is rounded to 3.0.
If I want to round to the nearest even, that is
my_round(1.5) = 2# As expected
my_round(2.5) = 2# Not 3, which is an odd num
I'm interested in rounding numbers of the f
45 matches
Mail list logo