Could not convert string to float

This is the place for queries that don't fit in any of the other categories.

Could not convert string to float

Postby Rovester » Sun Sep 25, 2016 8:50 pm

Hello i'm new to python and i need some help, basically i get the error 'Could not convert string to float'.
I've been looking around for it but i can't seem to find things like what i have or i'm just dumb.

Code: Select all
euro = float(input('Hoeveel euro?: '))
conv_fac = 1.12265

dollars = euro * conv_fac
print("%0.2f € is gelijk aan %0.2f $" %(euro,dollars))
input("Druk op enter om te sluiten.")
Last edited by ichabod801 on Sun Sep 25, 2016 8:57 pm, edited 1 time in total.
Reason: First post lock
Rovester
 
Posts: 2
Joined: Sun Sep 25, 2016 8:47 pm

Re: Could not convert string to float

Postby ichabod801 » Sun Sep 25, 2016 8:58 pm

What string did you enter that would not convert to float?
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801
 
Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: Could not convert string to float

Postby Rovester » Sun Sep 25, 2016 9:06 pm

ichabod801 wrote:What string did you enter that would not convert to float?

I just tried 5
Rovester
 
Posts: 2
Joined: Sun Sep 25, 2016 8:47 pm

Re: Could not convert string to float

Postby Skaperen » Mon Sep 26, 2016 2:15 am

make a tiny python script that illustrates your case. be sure it does nothing else. then show your results.
Code: Select all
lt1/forums /home/forums 6> cat convert-string-to-float.py
from __future__ import print_function
s='5'
f=float(s)
print(f)
lt1/forums /home/forums 7> python2 convert-string-to-float.py
5.0
lt1/forums /home/forums 8> python3 convert-string-to-float.py
5.0
lt1/forums /home/forums 9>
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016. This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
Skaperen
 
Posts: 267
Joined: Tue Apr 07, 2015 9:58 am
Location: Wheeling WV USA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 12 guests