Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ValueError: could not convert string to float
QtWS25 Last Chance

ValueError: could not convert string to float

Scheduled Pinned Locked Moved Unsolved General and Desktop
pyqt5python3
4 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YassineKira
    wrote on 22 Dec 2020, 23:33 last edited by YassineKira
    #1

    Hello everyone, hope you are all well :). First i search in my database, i change the tuple into a list then i want change a list of string to a list of foat so i can manipulate the value.

    I make the type in database in string i dont know if i have to change it, tell me ?

    I dont know what is wrong, thanks in advance

    the lists :

    [('78,38',), ('100,40745',), ('90,75',), ('110,32',), ('89,6',)]
    ['78,38', '100,40745', '90,75', '110,32', '89,6']
    

    the error :

    ValueError: could not convert string to float: '78,38'
    
                searchrol = "Isolation Thermique par l'Extérieur"
                cursor = db.cursor()
                result_5 = cursor.execute("SELECT prix FROM PU WHERE desig_pu= ?  ", (str(searchrol),))
                row_5 = result_5.fetchall()
                print(row_5)
                liste = []
                my_list = [] 
                for tupl in row_5: # initialisation de liste
                    for i in tupl: 
                        liste.append(i)  
                print (liste) # afficher la liste
                my_list = [float(i) for i in liste]
                #my_list = list(map(float, liste))
                #print(type(liste[0]))
                print (my_list)
                BT = 113.2
                BT0 = 113.4
                row_actualise = []
                for x in liste:
                    y = x*(BT/BT0)
                    row_actualise.append(str(y))
                print(row_actualise)
    ![Capture.PNG](https://ddgobkiprc33d.cloudfront.net/98bca980-012f-474c-a7a5-6d98ccc93e80.PNG) ![Capture1.PNG](https://ddgobkiprc33d.cloudfront.net/573582f4-7e1d-412b-ab7a-cf6cc2f0e590.PNG)
    K J 2 Replies Last reply 23 Dec 2020, 07:02
    0
    • Y YassineKira
      22 Dec 2020, 23:33

      Hello everyone, hope you are all well :). First i search in my database, i change the tuple into a list then i want change a list of string to a list of foat so i can manipulate the value.

      I make the type in database in string i dont know if i have to change it, tell me ?

      I dont know what is wrong, thanks in advance

      the lists :

      [('78,38',), ('100,40745',), ('90,75',), ('110,32',), ('89,6',)]
      ['78,38', '100,40745', '90,75', '110,32', '89,6']
      

      the error :

      ValueError: could not convert string to float: '78,38'
      
                  searchrol = "Isolation Thermique par l'Extérieur"
                  cursor = db.cursor()
                  result_5 = cursor.execute("SELECT prix FROM PU WHERE desig_pu= ?  ", (str(searchrol),))
                  row_5 = result_5.fetchall()
                  print(row_5)
                  liste = []
                  my_list = [] 
                  for tupl in row_5: # initialisation de liste
                      for i in tupl: 
                          liste.append(i)  
                  print (liste) # afficher la liste
                  my_list = [float(i) for i in liste]
                  #my_list = list(map(float, liste))
                  #print(type(liste[0]))
                  print (my_list)
                  BT = 113.2
                  BT0 = 113.4
                  row_actualise = []
                  for x in liste:
                      y = x*(BT/BT0)
                      row_actualise.append(str(y))
                  print(row_actualise)
      ![Capture.PNG](https://ddgobkiprc33d.cloudfront.net/98bca980-012f-474c-a7a5-6d98ccc93e80.PNG) ![Capture1.PNG](https://ddgobkiprc33d.cloudfront.net/573582f4-7e1d-412b-ab7a-cf6cc2f0e590.PNG)
      K Offline
      K Offline
      KroMignon
      wrote on 23 Dec 2020, 07:02 last edited by
      #2

      @YassineKira This has nothing to do with Qt, this is a Python script issue

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      Y 1 Reply Last reply 23 Dec 2020, 13:57
      4
      • Y YassineKira
        22 Dec 2020, 23:33

        Hello everyone, hope you are all well :). First i search in my database, i change the tuple into a list then i want change a list of string to a list of foat so i can manipulate the value.

        I make the type in database in string i dont know if i have to change it, tell me ?

        I dont know what is wrong, thanks in advance

        the lists :

        [('78,38',), ('100,40745',), ('90,75',), ('110,32',), ('89,6',)]
        ['78,38', '100,40745', '90,75', '110,32', '89,6']
        

        the error :

        ValueError: could not convert string to float: '78,38'
        
                    searchrol = "Isolation Thermique par l'Extérieur"
                    cursor = db.cursor()
                    result_5 = cursor.execute("SELECT prix FROM PU WHERE desig_pu= ?  ", (str(searchrol),))
                    row_5 = result_5.fetchall()
                    print(row_5)
                    liste = []
                    my_list = [] 
                    for tupl in row_5: # initialisation de liste
                        for i in tupl: 
                            liste.append(i)  
                    print (liste) # afficher la liste
                    my_list = [float(i) for i in liste]
                    #my_list = list(map(float, liste))
                    #print(type(liste[0]))
                    print (my_list)
                    BT = 113.2
                    BT0 = 113.4
                    row_actualise = []
                    for x in liste:
                        y = x*(BT/BT0)
                        row_actualise.append(str(y))
                    print(row_actualise)
        ![Capture.PNG](https://ddgobkiprc33d.cloudfront.net/98bca980-012f-474c-a7a5-6d98ccc93e80.PNG) ![Capture1.PNG](https://ddgobkiprc33d.cloudfront.net/573582f4-7e1d-412b-ab7a-cf6cc2f0e590.PNG)
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 23 Dec 2020, 08:02 last edited by jsulm
        #3

        @YassineKira said in ValueError: could not convert string to float:

        ValueError: could not convert string to float: '78,38'

        You know that floating point numbers in Python (and all other programming languages I know) use a dot instead of a colon?!
        So, 78,38 is NOT a floating POINT number! 78.38 is a floating point number. You should learn the basic stuff first...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        5
        • K KroMignon
          23 Dec 2020, 07:02

          @YassineKira This has nothing to do with Qt, this is a Python script issue

          Y Offline
          Y Offline
          YassineKira
          wrote on 23 Dec 2020, 13:57 last edited by YassineKira
          #4

          @KroMignon Well, i try to learn from anothers in every forum, sorry :), @jsulm Thank you Sir, you are a Life saver :)

          1 Reply Last reply
          0

          1/4

          22 Dec 2020, 23:33

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved