Problem with computing...addition

Lukas Kasprowicz nospam at maniacxs.de
Tue Aug 12 13:37:02 EDT 2003


Hi Folks,
I have some code, have tested the output, and I have seen the mess !!!!

here the code:

def fee(data):
  from re import sub, findall
  from string import join, split
  fee = sub('.*?EUR', '', data)
  fee = findall('.*,..', fee)
  print fee
  zwischensumme = float("0")
  for i in range(int(len(fee))):
    fee[i] = join(split(fee[i], ","), ".")
    fee[i] = float(fee[i])
    zwischensumme = zwischensumme + fee[i]
    print zwischensumme
  print zwischensumme
  print int(len(fee))
  print fee
def main(data,vendor,type):
  print data
  fee(data)


it begins in the main(). the output of "print data" in main is:

-------------cut -----------------
* Nokia 6610 NEU & OVP * 2 Jahre Garantie *             EUR 198,0016 18Min
Nokia 6610 + Camera Headset HS-1C ** NEU **             EUR 221,0033 1Std
17Min
NOKIA 6610 NEU + OVP + GARANTIE !!ANGUCKEN!!!           EUR 181,0012 1Std
57Min
Nokia 6610 OVP *neu*            EUR 176,0025 17Std 35Min
Nokia 6610, OVP, neu            EUR 126,622 21Std 12Min
Nokia 6610, Originalverpackt, WIE NEU !!                EUR 113,0010 21Std
39Min
Nokia 6610 ***NEU***            EUR 329,00- 21Std 42Min
+++NOKIA 6610 NEU in OVP in grau+++             EUR 133,00101T 00Std 57Min
NOKIA 6610 NEU OVP GARANTIE RECHNUNG !!         EUR 151,0061T 01Std 12Min
Nokia 6610 NEU OVP 24 Monate Garantie           EUR 152,0081T 01Std 30Min
NOKIA 6610 BLACK NEU und OVP KEIN VERTRAG !!!           EUR 152,00161T 01Std
50Min
Nokia 6610 - NEU                EUR 152,0081T 02Std 28Min
* NOKIA 6610 NEU*OVP*Silber*GARANTIE*Headset*           EUR 152,0091T 02Std
39Min
Nokia 6610 (NEU/OVP/ 2 JAHRE GARANTIE)          EUR 152,00111T 02Std 44Min
* Nokia 6610 grey * NEU + OVP + 2 J. Garantie           EUR 131,99121T 02Std
49Min
Nokia 6610  Neu ohne SimLock OVP mit Camera             EUR 153,27231T 03Std
49Min
NOKIA 6610, NEU, Ungebraucht, Silber!!!         EUR 175,00-1T 18Std 14Min
---------------- cut -----------

everything in front of "EUR" is cut off.
the fee is searched, and printed. the output of <fee> is:

[' 198,00', ' 221,00', ' 181,00', ' 176,00', ' 126,62', ' 113,00', '
329,00', ' 133,00', ' 151,00', ' 152,00', ' 152,00', ' 152,00', ' 152,00',
' 152,00', ' 131,99', ' 153,27', ' 175,00', ' 175,00', ' 68,00', ' 45,50',
' 26,50', ' 71,00', ' 152,00', ' 61,00', ' 101,00', ' 259,00', ' 151,00', '
20,50', ' 1,00', ' 66,00', ' 200,00', ' 200,00', ' 1,00', ' 81,00', '
1,00', ' 1,00', ' 25,50', ' 53,00', ' 240,00', ' 1,00', ' 25,50', ' 1,50',
' 101,00', ' 3,05', ' 1,00', ' 239,00', ' 15,50', ' 1,00', ' 10,00', '
1,99']

so everything seems to be ok now....
but ...
after the "," is changed to an "." and the field of the list is converted to
float, the output looks like this:

[198.0, 221.0, 181.0, 176.0, 126.62, 113.0, 329.0, 133.0, 151.0, 152.0,
152.0, 152.0, 152.0, 152.0, 131.99000000000001, 153.27000000000001, 175.0,
175.0, 68.0, 45.5, 26.5, 71.0, 152.0, 61.0, 101.0, 259.0, 151.0, 20.5, 1.0,
66.0, 200.0, 200.0, 1.0, 81.0, 1.0, 1.0, 25.5, 53.0, 240.0, 1.0, 25.5, 1.5,
101.0, 3.0499999999999998, 1.0, 239.0, 15.5, 1.0, 10.0, 1.99]

So you see e.g. the 15th entry: "131.99000000000001"

there should be "131.99" and not this.


who could help?
-- 
---------------------------------------------------------
Das einzige Mittel gegen Aberglauben ist Wissenschaft.
(Henry Thomas Buckle)




More information about the Python-list mailing list