round probleme under python 2.0 
Author Message
 round probleme under python 2.0

good morning.

I have a problem with python 2.0 under gnu linux debian/sid.
round seem not working well. any idea to solve the problem?

Thanks for any answers.

_________________
Under Python 2.0

Quote:
>>> b
2.8465416541454847
>>> [v,b]

[31.665164691616152, 2.8465416541454847]
Quote:
>>> [round(v,2),round(b,2)]

[31.670000000000002, 2.8500000000000001]
Quote:
>>> round(v,2)

31.670000000000002

_________________________________
under python 1.5

Quote:
>>> v=31.665164691616151351651654651651
>>> v
31.6651646916
>>> b=2.84654165414548456465165651651651465
>>> b
2.84654165415
>>> [v,b]

[31.6651646916, 2.84654165415]
Quote:
>>> [round(v,2),round(b,2)]
[31.67, 2.85]

--
                            \\\|///
                          \\  - -  //

+-----------------------oOOo-(_)-oOOo--------------------+
|Famy William  36 avenue des barattes 74000 Annecy France|


+--------------------------------Oooo--------------------+
                           oooO   (   )
                          (   )    ) /
                           \ (    (_/
                            \_)


Wed, 05 Nov 2003 23:44:46 GMT  
 round probleme under python 2.0

Quote:

> good morning.

> I have a problem with python 2.0 under gnu linux debian/sid.
> round seem not working well. any idea to solve the problem?

> Thanks for any answers.

> _________________
> Under Python 2.0

>>>> b
> 2.8465416541454847
>>>> [v,b]
> [31.665164691616152, 2.8465416541454847]
>>>> [round(v,2),round(b,2)]
> [31.670000000000002, 2.8500000000000001]
>>>> round(v,2)
> 31.670000000000002

As far as I understand, 1.5 was lying to you. If you want
2.0+ to lie also, you can either use
Quote:
>>> print round(v,2)

31.67
or
Quote:
>>> repr(round(v,2))

31.67

- Show quoted text -

Quote:

> _________________________________
> under python 1.5

>>>> v=31.665164691616151351651654651651
>>>> v
> 31.6651646916
>>>> b=2.84654165414548456465165651651651465
>>>> b
> 2.84654165415
>>>> [v,b]
> [31.6651646916, 2.84654165415]
>>>> [round(v,2),round(b,2)]
> [31.67, 2.85]

> --
>                             \\\|///
>                           \\  - -  //

> +-----------------------oOOo-(_)-oOOo--------------------+
>|Famy William  36 avenue des barattes 74000 Annecy France|


> +--------------------------------Oooo--------------------+
>                            oooO   (   )
>                           (   )    ) /
>                            \ (    (_/
>                             \_)

--
Jupiter and Saturn Oberon Miranda
And Titania Neptune Titan
Stars can frighten
        - Syd


Wed, 05 Nov 2003 23:58:48 GMT  
 round probleme under python 2.0


Quote:

>I have a problem with python 2.0 under gnu linux debian/sid.
>round seem not working well. any idea to solve the problem?

Welcome to the fun of floating point.  If you like the idea of exact
answers, you might want to try being one of the testers for my new
Decimal.py (currently supports only addition and subtraction).  If you
can't wait, try FixedPoint.py.
--

Androgynous poly {*filter*} vanilla {*filter*} het Pythonista   http://www.*-*-*.com/
Hugs and backrubs -- I break Rule 6

Cole's Law: thinly sliced cabbage



Thu, 06 Nov 2003 00:46:03 GMT  
 round probleme under python 2.0
Sez William Famy:

Quote:
> I have a problem with python 2.0 under gnu linux debian/sid.
> round seem not working well. any idea to solve the problem?

It works.  The only thing changed is how it's printed.  Floats are now by
default repr'd more exactly.  Search googlegroups for floating point, and
you'll see that you're not the first one to discover this.

Also:
http://www.python.org/cgi-bin/moinmoin/FrequentlyAskedQuestions#line24

Quote:
> _________________
> Under Python 2.0

> >>> b
> 2.8465416541454847
> >>> [v,b]
> [31.665164691616152, 2.8465416541454847]
> >>> [round(v,2),round(b,2)]
> [31.670000000000002, 2.8500000000000001]
> >>> round(v,2)
> 31.670000000000002

These are correct.  Try

Quote:
>>> print round(v, 2)
or
>>> str(round(v, 2))

Peace,
  Kalle
--

Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]


Thu, 06 Nov 2003 00:30:53 GMT  
 round probleme under python 2.0

Quote:

> Welcome to the fun of floating point.  If you like the idea of exact
> answers, you might want to try being one of the testers for my new
> Decimal.py (currently supports only addition and subtraction).  If you
> can't wait, try FixedPoint.py.

_____________________________________
wf:
Ok and thanks for the solution but i can't print in a file 0.20000000000000001
instead of 0.2 !!
I will try FixedPoint.py. I am ready to test your decimal.py but i am a python
newbe and i do not a very fluent english. so tell me how help you for the
decimal.py and i will do my best.

Regards and thanks for the answer you gave me.

--
                            \\\|///
                          \\  - -  //

+-----------------------oOOo-(_)-oOOo--------------------+
|Famy William  36 avenue des barattes 74000 Annecy France|


+--------------------------------Oooo--------------------+
                           oooO   (   )
                          (   )    ) /
                           \ (    (_/
                            \_)



Thu, 06 Nov 2003 01:35:11 GMT  
 round probleme under python 2.0


Quote:

>I will try FixedPoint.py. I am ready to test your decimal.py but i am
>a python newbe and i do not a very fluent english. so tell me how help
>you for the decimal.py and i will do my best.

If you're that new to Python, just stick with FixedPoint.py for now;
Decimal.py requires a fair amount of Python knowledge currently.
--

Androgynous poly {*filter*} vanilla {*filter*} het Pythonista   http://www.*-*-*.com/
Hugs and backrubs -- I break Rule 6

Cole's Law: thinly sliced cabbage



Thu, 06 Nov 2003 02:57:28 GMT  
 round probleme under python 2.0

Quote:

>Sez William Famy:
>> I have a problem with python 2.0 under gnu linux debian/sid.
>> round seem not working well. any idea to solve the problem?

>It works.  The only thing changed is how it's printed.  Floats are now by
>default repr'd more exactly.  Search googlegroups for floating point, and
>you'll see that you're not the first one to discover this.

Not even the first one this week... ;)

--
Grant Edwards                   grante             Yow!  A shapely CATHOLIC
                                  at               SCHOOLGIRL is FIDGETING
                               visi.com            inside my costume...



Thu, 06 Nov 2003 03:05:25 GMT  
 round probleme under python 2.0

KS> Sez William Famy:

Quote:
>> I have a problem with python 2.0 under gnu linux debian/sid.
>> round seem not working well. any idea to solve the problem?

KS> It works.  The only thing changed is how it's printed.  Floats are now by
KS> default repr'd more exactly.  Search googlegroups for floating point, and
KS> you'll see that you're not the first one to discover this.

Is floating-point confusion a virus or other contagious disease?
--

URL: http://www.cs.uu.nl/~piet [PGP]



Fri, 07 Nov 2003 01:43:45 GMT  
 round probleme under python 2.0

Quote:

> Ok and thanks for the solution but i can't print in a file 0.20000000000000001
> instead of 0.2 !!
> I will try FixedPoint.py. I am ready to test your decimal.py but i am a python
> newbe and i do not a very fluent english. so tell me how help you for the
> decimal.py and i will do my best.

Yeah well i do not a very fluent french either, but here goes:

Si vous ne voulez pas "0.20000000000000001", essayez ceci:

   print "%.4f" % foo

Ce donne "0.2000" ...

A propos de votre ".sig", est-ce possible que "FW" == "Fils de Warlord"?

Quote:

> --
>                             \\\|///
>                           \\  - -  //

> +-----------------------oOOo-(_)-oOOo--------------------+
> |Famy William  36 avenue des barattes 74000 Annecy France|


> +--------------------------------Oooo--------------------+
>                            oooO   (   )
>                           (   )    ) /
>                            \ (    (_/
>                             \_)



Fri, 07 Nov 2003 12:07:13 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Rounding error in Python 2.0

2. Rounding Bug in Python 2.0! - ugh

3. Rounding Bug in Python 2.0! - ugh

4. Python 2.0 and wxPython 2.0

5. round rounds right?

6. Round and Round we go

7. Python 2.0 or Activestate Python?

8. kjbuckets for Python 2.0 (was Re: Sets in Python)

9. python-ldap binary for Python 2.0 under Win32

10. Embedded Python (MSVC++ & Python 2.0)

11. Building for Win64 (was: Re: [Python-Dev] Re: Python 2.0 release candidate 1)

12. Round Bug in Python 1.6?

 

 
Powered by phpBB® Forum Software