1

I'm now programming ecg signal with python and i have this error i dont know how i can solve it.

ValueError: could not convert string to float: '-0,274697\n'

enter image description here

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
Abdel
  • 11
  • 1
  • 2
  • 3
    Please post your code **as text**, using a formatted block, into the question. Thanks. – halfer Feb 02 '17 at 22:58
  • in consol i got this File "C:/Users/Imrane/Desktop/WinPython-64bit-3.5.2.3Qt5/settings/.spyder-py3/temp.py", line 121, in rateKommentar return float(datei.readline().replace('#','')) ValueError: could not convert string to float: '-0,274697\n' – Abdel Feb 02 '17 at 22:58
  • Hi welcome to StackOverflow. Could you please type your code out instead of having it in a picture. Also, on which line is the error occurring. (There are multiple conversions to float in the code you have posted) – cjds Feb 02 '17 at 23:02

1 Answers1

3

Okay, so you are trying to convert a string with a , to a floating point number.

In Python, you can't have a comma in your number, only a . is supported. To convert it, you can use these lines

 datei= open(dateiname,'r')
 dateistr = datei.readline().replace(',','.') #replacing comma with .
 dateistr = dateistr.replace('#','') # replacing # with blank
 dateistr = dateistr.strip('\n') #remove the new line character at the end
 return float(dateistr)
cjds
  • 8,268
  • 10
  • 49
  • 84