Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ValueError: could not convert string to float



  • 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)


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


  • Lifetime Qt Champion

    @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...



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


Log in to reply