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()
                liste = []
                my_list = [] 
                for tupl in row_5: # initialisation de liste
                    for i in tupl: 
                print (liste) # afficher la liste
                my_list = [float(i) for i in liste]
                #my_list = list(map(float, liste))
                print (my_list)
                BT = 113.2
                BT0 = 113.4
                row_actualise = []
                for x in liste:
                    y = x*(BT/BT0)
    ![Capture.PNG]( ![Capture1.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