Re: round decimal values

2021-06-24 Thread jo
Il Thu, 24 Jun 2021 18:07:07 +0200, Julio Di Egidio ha scritto: > On 24/06/2021 16:23, jo wrote: >> Hi, >> >> this code generate 4 values with gaussian distribution (mu=5, sigma=1): >> >> import numpy as np x = np.random.normal(5, 1, 4) >> print(x) >> >> Output: >> [5.87879753 3.29162433 3.8302

Re: round

2018-06-07 Thread Steven D'Aprano
On Thu, 07 Jun 2018 13:09:18 +0200, ast wrote: > Hi > > round is supposed to provide an integer when called without any > precision argument. True, but that's really under the control of the object you feed it to. It would be possible for round() to enforce that, but it might break code that r

Re: round

2018-06-07 Thread Peter Otten
ast wrote: > Hi > > round is supposed to provide an integer when > called without any precision argument. > > here is the doc: > > >>> help(round) > > round(number[, ndigits]) -> number > > Round a number to a given precision in decimal digits (default 0 digits). > This returns an int when c

Re: round

2018-06-07 Thread Lutz Horn
M = np.array([[0, 9],[2, 7]], dtype=int) np.linalg.det(M) -18.004 round(np.linalg.det(M)) np.linalg.det(M) has type numpy.float64, not float. Try this: round(float(np.linalg.det(M))) -18 Lutz -- https://mail.python.org/mailman/listinfo/python-list

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 01:31 pm, nick martinez wrote: > interesting, what version of python are you using? Tried it multiple times > and it still isn't working. Please launch a terminal window, copy this command exactly into the terminal and hit ENTER. You should have a $ or maybe % prompt for this

Re: Round to 2 decimal places

2017-12-06 Thread Steve D'Aprano
On Thu, 7 Dec 2017 11:58 am, nick martinez wrote: > I'm stuck. I need my program to round the end solution to 2 decimal places > but cant figure it out. Can someone help? I've been trying between printf > and round() but cant seem to get either to work. It might help if you show exactly what valu

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 9:32:27 PM UTC-5, nick martinez wrote: > On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot...@gmail.com wrote: > > On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > > > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 9:03:27 PM UTC-5, ssghot...@gmail.com wrote: > On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com > > wrote: > > > The following works: > > > > > > import math > >

Re: Round to 2 decimal places

2017-12-06 Thread MRAB
On 2017-12-07 01:39, nick martinez via Python-list wrote: On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com wrote: The following works: import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
On Thursday, December 7, 2017 at 12:39:38 PM UTC+11, nick martinez wrote: > On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com wrote: > > The following works: > > > > import math > > > > print("This program will calculate the surface area and volume of a > > 3-dimensional co

Re: Round to 2 decimal places

2017-12-06 Thread nick martinez via Python-list
On Wednesday, December 6, 2017 at 8:13:36 PM UTC-5, ssghot...@gmail.com wrote: > The following works: > > import math > > print("This program will calculate the surface area and volume of a > 3-dimensional cone: ") > print() > print() > r = input("What is the radius in feet? (no negatives): ") >

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What is the radius in feet? (no negatives): ") h = input("What is the height in feet? (no negatives): ") r = float(r) h = float(h) if r > 0 and h > 0: surfacearea

Re: Round to 2 decimal places

2017-12-06 Thread ssghotra1997
The following works: import math print("This program will calculate the surface area and volume of a 3-dimensional cone: ") print() print() r = input("What is the radius in feet? (no negatives): ") h = input("What is the height in feet? (no negatives): ") r = float(r) h = float(h) if r > 0 and h

Re: round off to two decimal & return float

2013-04-01 Thread ஆமாச்சு
On Saturday 30 March 2013 03:14 PM, Peter Otten wrote: > style = xlwt.XFStyle() > style.num_format_str = "0.00" Yes. That was really helpful & what I expected. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: round off to two decimal & return float

2013-03-30 Thread rurpy
On 03/30/2013 10:41 AM, Dennis Lee Bieber wrote: > On Sat, 30 Mar 2013 13:22:59 +0530, ??? declaimed > the following in gmane.comp.python.general: > >> Consider the scenario, >> >> >> a = 10 >> >> "{0:.2f}".format(a) >> '10.00' >> >> This returns a string 10.00. But what is the preferred me

Re: round off to two decimal & return float

2013-03-30 Thread Grant Edwards
On 2013-03-30, ? wrote: > On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: >> >> >> >> 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(): > > But I need 10.00 and not 10.0 They're the same

Re: round off to two decimal & return float

2013-03-30 Thread Roland Mueller
2013/3/30 Roland Mueller > Hello, > > 2013/3/30 ஆமாச்சு > >> 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 w

Re: round off to two decimal & return float

2013-03-30 Thread Peter Otten
ஆமாச்சு wrote: > 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)? You can use round() to convert 1.226 to 1.23 >>> round(1.225, 2) 1.23 for example, but 10.0 and 1

Re: round off to two decimal & return float

2013-03-30 Thread ஆமாச்சு
On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: > > > > 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(): But I need 10.00 and not 10.0 -- http://mail.python.org/mailman/listinfo/python-list

Re: round off to two decimal & return float

2013-03-30 Thread pyplexed
Hi Sri. I'm not familiar with the xlwt module, but I think you are confusing two different things here. Generally spreadsheets separate out how they handle the value in a cell (the value) and how that value is displayed (the format). This means that the you leave the cell value unchanged when

Re: round off to two decimal & return float

2013-03-30 Thread Roland Mueller
Hello, 2013/3/30 ஆமாச்சு > 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 c

Re: round down to nearest number

2012-02-11 Thread Hrvoje Niksic
Terry Reedy writes: > On 2/9/2012 8:23 PM, noydb wrote: >> So how would you round UP always? Say the number is 3219, so you want (//100+1)*100 > 3400 Note that that doesn't work for numbers that are already round: >>> (3300//100+1)*100 3400# 3300 would be correct I'd go with Chri

Re: round down to nearest number

2012-02-10 Thread Olive
On Thu, 9 Feb 2012 17:43:58 -0800 Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > > hmmm, okay. > > > > So how would you round UP always?  Say the number is 3219, so you > > want 3300 returned. > > http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integ

Re: round down to nearest number

2012-02-10 Thread noydb
On Feb 10, 4:58 am, Arnaud Delobelle wrote: > On 10 February 2012 06:21, Ian Kelly wrote: > > > > > > > (3219 + 99) // 100 * 100 > >> 3300 > > (3289 + 99) // 100 * 100 > >> 3300 > > (328678 + 99) // 100 * 100 > >> 328700 > > (328 + 99) // 100 * 100 > >> 400 > > >> Those are all ro

Re: round down to nearest number

2012-02-10 Thread Alec Taylor
o.O Very nice On Fri, Feb 10, 2012 at 8:58 PM, Arnaud Delobelle wrote: > On 10 February 2012 06:21, Ian Kelly wrote: >> (3219 + 99) // 100 * 100 >>> 3300 >> (3289 + 99) // 100 * 100 >>> 3300 >> (328678 + 99) // 100 * 100 >>> 328700 >> (328 + 99) // 100 * 100 >>> 400 >>> >>> Thos

Re: round down to nearest number

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 06:21, Ian Kelly wrote: > (3219 + 99) // 100 * 100 >> 3300 > (3289 + 99) // 100 * 100 >> 3300 > (328678 + 99) // 100 * 100 >> 328700 > (328 + 99) // 100 * 100 >> 400 >> >> Those are all rounded up to the nearest 100 correctly. > > One thing to be aware of though

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:36 PM, MRAB wrote: > On 10/02/2012 02:25, noydb wrote: >> >> That {>>>  (3219 + 99) // 100} doesnt work if the number is other then >> 4 digits. >> >> >> (for rounding up to nearest 100): > >  (3219 + 99)//100 >> >> 33 > >  (3289 + 99)//100 >> >> 33 > >

Re: round down to nearest number

2012-02-09 Thread MRAB
On 10/02/2012 03:29, Terry Reedy wrote: On 2/9/2012 8:23 PM, noydb wrote: So how would you round UP always? Say the number is 3219, so you want >>> (//100+1)*100 3400 Doing it that way doesn't always work. For example: >>> (3400 // 100 + 1) * 100 3500 However: >>> (3400 + 99) // 1

Re: round down to nearest number

2012-02-09 Thread MRAB
On 10/02/2012 02:25, noydb wrote: That {>>> (3219 + 99) // 100} doesnt work if the number is other then 4 digits. (for rounding up to nearest 100): (3219 + 99)//100 33 (3289 + 99)//100 33 (328678 + 99)//100 3287 (328 + 99)//100 4 >>> (3219 + 99) // 100 * 100 3300 >>> (3289 + 99)

Re: round down to nearest number

2012-02-09 Thread Terry Reedy
On 2/9/2012 8:23 PM, noydb wrote: So how would you round UP always? Say the number is 3219, so you want >>> (//100+1)*100 3400 -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread noydb
That {>>> (3219 + 99) // 100} doesnt work if the number is other then 4 digits. (for rounding up to nearest 100): >>> (3219 + 99)//100 33 >>> (3289 + 99)//100 33 >>> (328678 + 99)//100 3287 >>> (328 + 99)//100 4 -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 6:43 PM, Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: >> hmmm, okay. >> >> So how would you round UP always?  Say the number is 3219, so you want >> 3300 returned. > > http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-divis

Re: round down to nearest number

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > hmmm, okay. > > So how would you round UP always?  Say the number is 3219, so you want > 3300 returned. http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division/96921 Thus: (3219 + 99) // 100 Slight tangent: Beware ne

Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:40 PM, Chris Kaynor wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > >> hmmm, okay. >> >> So how would you round UP always? Say the number is 3219, so you want >> 3300 returned. >> > > You may want to look into the mathematical floor and ceiling functions[1]. > Py

Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > hmmm, okay. > > So how would you round UP always? Say the number is 3219, so you want > 3300 returned. > You may want to look into the mathematical floor and ceiling functions[1]. Python exposes them in the math module as floor and ceil[2]. [1] ht

Re: round down to nearest number

2012-02-09 Thread noydb
hmmm, okay. So how would you round UP always? Say the number is 3219, so you want 3300 returned. -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 5:30 PM, noydb wrote: > How do you round down ALWAYS to nearest 100?  Like, if I have number > 3268, I want that rounded down to 3200.  I'm doing my rounding like round(3268, -2) > But, how to round DOWN? >>> 3268 // 100 * 100 3200 For more complicated cases, Decimal

Re: round in 2.6 and 2.7

2010-12-29 Thread Mark Dickinson
On Dec 28, 9:47 pm, "Martin v. Loewis" wrote: > >> "Float-to-string and string-to-float conversions are correctly rounded. > >> The round() function is also now correctly rounded." > > >> Not sure that this is correct English; I think it means that the > >> round() function is now correct. > > > W

Re: round in 2.6 and 2.7

2010-12-28 Thread Terry Reedy
On 12/28/2010 4:47 PM, Martin v. Loewis wrote: "Float-to-string and string-to-float conversions are correctly rounded. The round() function is also now correctly rounded." The second line was written to be parallel to the first, but the first is slightly ambiguous in that 'conversions' can ref

Re: round in 2.6 and 2.7

2010-12-28 Thread Martin v. Loewis
>> "Float-to-string and string-to-float conversions are correctly rounded. >> The round() function is also now correctly rounded." >> >> Not sure that this is correct English; I think it means that the >> round() function is now correct. > > Well, the correct result of the example the OP gave woul

Re: round in 2.6 and 2.7

2010-12-27 Thread Mark Dickinson
On Dec 23, 6:57 pm, Hrvoje Niksic wrote: > I stumbled upon this.  Python 2.6: > > >>> round(9.95, 1) > > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. No, Python's not doing anything clever here. Python 2.6 us

Re: round in 2.6 and 2.7

2010-12-24 Thread Hrvoje Niksic
"Martin v. Loewis" writes: >> Type "help", "copyright", "credits" or "license" for more information. > 9.95 >> 9.9493 > "%.16g" % 9.95 >> '9.949' > round(9.95, 1) >> 10.0 >> >> So it seems that Python is going out of its way to intuitively round >> 9.95, while

Re: round in 2.6 and 2.7

2010-12-23 Thread Stefan Sonnenberg-Carstens
Am 23.12.2010 19:57, schrieb Hrvoje Niksic: I stumbled upon this. Python 2.6: Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. 9.95 9.9493 "%.16g" % 9.95 '9.949' round(9.95,

Re: round in 2.6 and 2.7

2010-12-23 Thread Martin v. Loewis
> Type "help", "copyright", "credits" or "license" for more information. 9.95 > 9.9493 "%.16g" % 9.95 > '9.949' round(9.95, 1) > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digit

Re: round in 2.6 and 2.7

2010-12-23 Thread macm
On Dec 23, 4:57 pm, Hrvoje Niksic wrote: > I stumbled upon this.  Python 2.6: > > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 9.95 > 9.9493 > >>> "%.16g" % 9.95 > '9.949

Re: Round Trip: C to Python to C Module

2010-11-22 Thread bobicanprogram
On Nov 19, 11:05 am, Eric Frederich wrote: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp.>Fr

Re: Round Trip: C to Python to C Module

2010-11-19 Thread Diez B. Roggisch
Eric Frederich writes: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp. >>From an interactive

Re: round issue

2010-07-13 Thread Emile van Sebille
On 7/13/2010 9:06 AM Robin Becker said... Anyhow does anyone have a good algorithm for ensuring rounded percentages do add up to 100%? :) How about grouped percentages ie ensure the group sums and the groups display correctly in rounded form. I generally do the calculations in memory then set

Re: round issue

2010-07-13 Thread Robin Becker
On 12/07/2010 19:59, Mark Dickinson wrote: It does look inconsistent however, and it seems to me rounding and interpolation should behave similarly. Agreed. In this case it's a minor bug that round(-9.85, 1) produces -9.9 instead of -9.8; both string formatting and round should g

Re: round issue

2010-07-12 Thread Mark Dickinson
Emile van Sebille fenx.com> writes: > > On 7/12/2010 2:52 AM Robin Becker said... > > > What value should round(-9.85,1) return? > > Per round's definition, -9.9. No. The float that's represented by the literal '-9.85' *isn't* exactly -9.85, for all the usual binary floating-point reasons. T

Re: round issue

2010-07-12 Thread Emile van Sebille
On 7/12/2010 2:52 AM Robin Becker said... What value should round(-9.85,1) return? Per round's definition, -9.9. String interpolation for %n.mf doesn't appear to define it's rounding behavior, so a peek at the source would answer what's being done. It does look inconsistent however, and i

Re: round issue

2010-07-12 Thread Gary Herron
On 07/12/2010 02:52 AM, Robin Becker wrote: A client wants to know why his db number -9.85 gets displayed by some simple code as -9.8 I looked at the number and see that >>> -9.85 -9.8496 ie I expect simple rounding to produce the observed result and indeed >>> '%.1f' % -9.85 '-9

Re: round issue

2010-07-12 Thread Mark Dickinson
On Jul 12, 10:52 am, Robin Becker wrote: > What value should round(-9.85,1) return? Is the result explainable in python > (ie > without resort to the internal FP representations etc etc)? As you observe, the closest float to -9.85 is actually just a little smaller (i.e., closer to 0) than -9.85:

Re: round() function

2010-02-25 Thread Michael Rudolf
Am 25.02.2010 16:39, schrieb Tracubik: hi all, i've this sample code: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico Thi

Re: round() function

2010-02-25 Thread Stefan Behnel
Tracubik, 25.02.2010 16:39: > hi all, i've this sample code: > n = 4.499 str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? Format the number

Re: round() function

2010-02-25 Thread mailing list
On 25.2.2010. 16:39, Tracubik wrote: hi all, i've this sample code: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advanc

Re: round() function

2010-02-25 Thread Tim Chase
Tracubik wrote: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. Use string formatting: >>> "%0.2f" % round(4.499, 2) '4.50' -tkc -- http://mail.python.org/mailma

Re: round function error???

2008-07-20 Thread John Machin
On Jul 21, 12:56 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Jul 19, 12:20 am, John Machin <[EMAIL PROTECTED]> wrote: > > > On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > > for more information. But I'm guessing that you're > > > questioning the fact that a value that's a

Re: round function error???

2008-07-20 Thread Mark Dickinson
On Jul 19, 12:20 am, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > for more information.  But I'm guessing that you're > > questioning the fact that a value that's apparently > > *less* than 3499.35 is rounded up to 3499.4, rather > > tha

Re: round function error???

2008-07-18 Thread John Machin
On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Jul 18, 10:17 pm, Anthony <[EMAIL PROTECTED]> wrote: > > > Isn't this a mistake??? > > Which 'this'? That is, what were you expecting? > > If you're objecting to the fact that the second result > produces 3499.34999 instead

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 11:15 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > No, round() return binary floats that, in general, cannot represent > decimal floats exactly.  Formatted printing gives what you expect. >  >>> '%8.2f' % x > ' 3499.35' Sure. But it's still true that the second printed value (printed a

Re: round function error???

2008-07-18 Thread Terry Reedy
Anthony wrote: Isn't this a mistake??? round(3499.349439034,44) 3499.3494390340002 round(_,2) 3499.34999 round(_,1) 3499.40001 My Python 2.5.1 spat that out.. No, round() return binary floats that, in general, cannot represent decimal floats exactly. Formatted printi

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 10:17 pm, Anthony <[EMAIL PROTECTED]> wrote: > Isn't this a mistake??? Which 'this'? That is, what were you expecting? If you're objecting to the fact that the second result produces 3499.34999 instead of 3499.35, then no, that's not a mistake; see http://www.python.org/doc/

Re: round-trip from egg to code and back to egg

2007-10-08 Thread John Nagle
Bruno Desthuilliers wrote: > Catherine a écrit : >> Three possibilities come to mind - >> >> 1. I'm missing something simple > > Probably. I'd say, something like unzip .egg !-) That's generally the solution to "egg" files. They usually do the wrong thing, and the "egg" system is still in be

Re: round-trip from egg to code and back to egg

2007-08-22 Thread Bruno Desthuilliers
Catherine a écrit : > I'd like to use Scriptaculous with TurboGears on Python 2.5. > Unfortunately, Scriptaculous is currently in the Cheese Shop only as a > Python 2.4 egg. > > If I had the setup.py that was used to generate the egg, I think it > would be really easy to generate a new Python 2.5

Re: round not rounding to 0 places

2006-08-16 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Tim Leslie <[EMAIL PROTECTED]> wrote: >On 16 Aug 2006 00:19:24 -0700, Fuzzydave <[EMAIL PROTECTED]> wrote: >> I have been using a round command in a few places to round >> a value to zero decimal places using the following format, >> >> round('+value+', 0) >> >> but

Re: round not rounding to 0 places

2006-08-16 Thread Fuzzydave
> Sybren Stuvel wrote: > round returns a float. Use > int(round('+value+', 0)) > to get an integer. > Sybren ahh of course it does, slaps own forehead sorted thanks :) David P -- http://mail.python.org/mailman/listinfo/python-list

Re: round not rounding to 0 places

2006-08-16 Thread Tim Leslie
On 16 Aug 2006 00:19:24 -0700, Fuzzydave <[EMAIL PROTECTED]> wrote: > I have been using a round command in a few places to round > a value to zero decimal places using the following format, > > round('+value+', 0) > > but this consistantly returns the rounded result of the value > to one decimal pl

Re: round not rounding to 0 places

2006-08-16 Thread Simon Forman
Fuzzydave wrote: > I have been using a round command in a few places to round > a value to zero decimal places using the following format, > > round('+value+', 0) > > but this consistantly returns the rounded result of the value > to one decimal place with a zero > > EG: > > 4.97 is returned as 5.0

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-17 Thread Bernhard Herzog
"Paul McGuire" <[EMAIL PROTECTED]> writes: > ... or if you prefer the functional approach (using map)... > > roundToInt = lambda z : int(z+0.5) > Topamax = map( roundToInt, map( float, map(str, Topamax) ) ) > > (Python also has a built-in round() function, but this returns floats, not > ints - if

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Scott David Daniels
Paul McGuire wrote: > ... or if you prefer the functional approach (using map)... > > roundToInt = lambda z : int(z+0.5) > Topamax = map( roundToInt, map( float, map(str, Topamax) ) ) Somehow, the list comprehension looks simpler and clearer to me: Topamax = [int(float(uni) + .5) for uni in

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Paul McGuire
"Lance Hoffmeyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The array comes out as unicode. This is probably because I am grabbing the numbers > from a Word Doc using regex's. > > So, before rounding I perform the following: > # Convert to String > Topamax = [str(x) for x in To

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Paul McGuire
"Lance Hoffmeyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The array comes out as unicode. This is probably because I am grabbing the numbers > from a Word Doc using regex's. > > So, before rounding I perform the following: > # Convert to String > Topamax = [str(x) for x in To

Re: round numbers in an array without importing Numeric or Math? - SOLVED, sort of

2006-05-16 Thread Lance Hoffmeyer
The array comes out as unicode. This is probably because I am grabbing the numbers from a Word Doc using regex's. So, before rounding I perform the following: # Convert to String Topamax = [str(x) for x in Topamax] # Convert to floating Topamax = [float(x) for x in Topamax] # Finally, round the

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Dan Sommers
On Tue, 16 May 2006 13:41:37 -0500, Lance Hoffmeyer <[EMAIL PROTECTED]> wrote: > May have a complicating issue with the array? Have > the numbers have been interpreted as strings? I have > been pulling them from a Word doc using regex's > print Test > [u'9.0', u'58.6', u'97.8', u'10.0', u'9.6',

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread skip
Lance> May have a complicating issue with the array? Have the numbers Lance> have been interpreted as strings? I have been pulling them from Lance> a Word doc using regex's [int(float(x)+0.5) for x in Test] S -- http://mail.python.org/mailman/listinfo/python-list

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Lance Hoffmeyer
May have a complicating issue with the array? Have the numbers have been interpreted as strings? I have been pulling them from a Word doc using regex's print Test [u'9.0', u'58.6', u'97.8', u'10.0', u'9.6', u'28.1'] Lance Alexander Schmolck wrote: > Lance Hoffmeyer <[EMAIL PROTECTED]> writes

Re: round numbers in an array without importing Numeric or Math?

2006-05-16 Thread Alexander Schmolck
Lance Hoffmeyer <[EMAIL PROTECTED]> writes: > Is there an easy way to round numbers in an array? > > I have > Test = [1.1,2.2,3.7] > > and want to round so the values are > > print Test [1,2,4] [int(x+0.5) for x in Test] 'as -- http://mail.python.org/mailman/listinfo/python-list

Re: Round

2006-04-09 Thread HeidiWeber
thank you very much to you i wish you a nice sunday... cu Heidi -- http://mail.python.org/mailman/listinfo/python-list

Re: Round

2006-04-09 Thread Ravi Teja
No! That is NOT correct Python. For one thing, you do not declare the types in dynamically typed languages. Secondly, if you want floating point division, you need to enter atleast one of the numbers as float. For example 10.0/6 or 10./6 or float(10)/6 You will find the following helpful. http://

Re: Round

2006-04-09 Thread Diez B. Roggisch
HeidiWeber wrote: > Hello > > i´m a beginner in python. With version 14 in SPSS (statistic software) > there are the posibility to use python. > > i want do the following: > > double NCases > NCases=10/6 > > is this correct in python? Because in SPSS there are an error message. No, its not co

Re: round() wrong in Python 2.4?

2005-09-15 Thread Antoon Pardon
Op 2005-09-14, Robert Kern schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-09-13, Robert Kern schreef <[EMAIL PROTECTED]>: >> >>>Jeremy Sanders wrote: >>> Nils Grimsmo wrote: >Why did round() change in Python 2.4? It the usual floating point representation prob

Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Robert Kern wrote: > Reinhold Birkenfeld wrote: > >>Robert Kern wrote: > >>>Antoon: >>>"Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down." >> >>Written in Pseudocode: >> >>not (Py2.3 rounding up and Py2.4 rounding down) > > I presumed the "isn't" was a typo given the "while."

Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Reinhold Birkenfeld wrote: > Robert Kern wrote: >>Antoon: >>"Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down." > > Written in Pseudocode: > > not (Py2.3 rounding up and Py2.4 rounding down) I presumed the "isn't" was a typo given the "while." -- Robert Kern [EMAIL PROTECTED

Re: round() wrong in Python 2.4?

2005-09-14 Thread Reinhold Birkenfeld
Robert Kern wrote: > Grant Edwards wrote: >> On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote: >> >>>Antoon Pardon wrote: >> 0.0225 isn't representable and it happens that the actual number you get differ. Now which number python should choose when it is fed 0.0225, I don't know.

Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Grant Edwards wrote: > On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote: > >>Antoon Pardon wrote: > >>>0.0225 isn't representable and it happens that the actual number >>>you get differ. Now which number python should choose when it is >>>fed 0.0225, I don't know. But expressing the different

Re: round() wrong in Python 2.4?

2005-09-14 Thread Magnus Lycka
Nils Grimsmo wrote: > (Is this due to the different GCC used?) Yes, but there are probably other nasty values with the other CGG. Basically, what the code does, for a positive number, is to calculate floor(0.0225*1000.0+0.5)/1000.0. As others have said: Don't trust this. If you use Python 2.4, yo

Re: round() wrong in Python 2.4?

2005-09-14 Thread Grant Edwards
On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: >> 0.0225 isn't representable and it happens that the actual number >> you get differ. Now which number python should choose when it is >> fed 0.0225, I don't know. But expressing the different behaviour >> as a change in

Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Antoon Pardon wrote: > Op 2005-09-13, Robert Kern schreef <[EMAIL PROTECTED]>: > >>Jeremy Sanders wrote: >> >>>Nils Grimsmo wrote: >>> Why did round() change in Python 2.4? >>> >>>It the usual floating point representation problem. 0.0225 cannot be >>>represented exactly: >> >>That's not what

Re: round() wrong in Python 2.4?

2005-09-14 Thread Antoon Pardon
Op 2005-09-13, Robert Kern schreef <[EMAIL PROTECTED]>: > Jeremy Sanders wrote: >> Nils Grimsmo wrote: >> >>>Why did round() change in Python 2.4? >> >> It the usual floating point representation problem. 0.0225 cannot be >> represented exactly: > > That's not what he's asking about. He's asking

Re: round() wrong in Python 2.4?

2005-09-14 Thread Jeremy Sanders
Robert Kern wrote: > That's not what he's asking about. He's asking why his Python 2.3 rounds > 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's > the change in behavior that he's concerned with and isn't just the usual > floating point problem. You can't rely on either bein

Re: round() wrong in Python 2.4?

2005-09-14 Thread Nils Grimsmo
I am running Debian unstable for 386. Python 2.4 is from the official package archive, and seems to be compiled with GCC 4.0.2. $ dpkg -l python2.4 ii python2.4 2.4.1-4 ... $ python2.4 Python 2.4.1+ (#2, Sep 4 2005, 21:58:51) [GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on l

Re: round() wrong in Python 2.4?

2005-09-13 Thread Sion Arrowsmith
Nils Grimsmo <[EMAIL PROTECTED]> wrote: >Why did round() change in Python 2.4? > >$ python2.3 >Python 2.3.5 (#2, Jun 19 2005, 13:28:00) >[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2 round(0.0225, 3) >0.023 "%.3f" % round(0.0225, 3) >'0.023' >$ python2.4 >Python 2.4.1 (#2, Jul 12 2005, 09

Re: round() wrong in Python 2.4?

2005-09-13 Thread Robert Kern
Jeremy Sanders wrote: > Nils Grimsmo wrote: > >>Why did round() change in Python 2.4? > > It the usual floating point representation problem. 0.0225 cannot be > represented exactly: That's not what he's asking about. He's asking why his Python 2.3 rounds 0.0225 *up* to 0.023 while his Python 2.4

Re: round() wrong in Python 2.4?

2005-09-13 Thread Jeremy Sanders
Nils Grimsmo wrote: > Why did round() change in Python 2.4? It the usual floating point representation problem. 0.0225 cannot be represented exactly: xpc20:~> python Python 2.3.4 (#1, Mar 14 2005, 16:47:22) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type "help", "copyright", "credits"

Re: round function problem

2005-09-06 Thread Bengt Richter
On Tue, 06 Sep 2005 09:27:48 +0200, mg <[EMAIL PROTECTED]> wrote: >Hi everybody... > >We try to white scripts with Pyrhon 2.4 for an acoustic simulation and >we wrote these follow lines : > > >c = 340 340 is an integer, which is different from 340. >i =j=k= 1 >sum_ = 23 also an integer >table = [

Re: round function problem

2005-09-06 Thread Magnus Lycka
mg wrote: > The problem is simple. The function 'round' allow to obtain the value > with the specified number of digits after the ",". Then, when the > variable 'freq' is printed, there is no problem; but when freq is set in > the table and the table printed, all the digits are come back. > > I

Re: round function problem

2005-09-06 Thread Gregory Bond
mg wrote: > Is it a bug or a control behavour ? I don't understand ?!?!?!?!... It's a case of applying different float-to-text rounding in different situations, on a variable that (even after round()) is not representable in binary floatingpoint. "print var" does one sort of string conversion

Re: round function problem

2005-09-06 Thread Fredrik Lundh
"mg" wrote: > We try to white scripts with Pyrhon 2.4 for an acoustic simulation and > we wrote these follow lines : > > > c = 340 > i =j=k= 1 > sum_ = 23 > table = [] > freq = round((c/2*(sum_)**0.5),2) > print freq > table.append([freq,(i,j,k)]) > print i,j,k,' freq',freq > for item in table: p