Hi, is there a conversion function/method to convert a string, say “0.15” to a float?
Nick
Dublin
String To Float
Re: String To Float
Here's the section of code:
BlinkStr = str(LED[-1])
BlinkStr = BlinkStr[6:]
print(BlinkStr)
#BlinkRate = float(BlinkStr)
>>> %Run -c $EDITOR_CONTENT
0.15
If I uncomment the float line then I get an error:
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 88, in <module>
ValueError: invalid syntax for number
BlinkStr = str(LED[-1])
BlinkStr = BlinkStr[6:]
print(BlinkStr)
#BlinkRate = float(BlinkStr)
>>> %Run -c $EDITOR_CONTENT
0.15
If I uncomment the float line then I get an error:
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 88, in <module>
ValueError: invalid syntax for number
Nick
Dublin
Unix Biker
Dublin
Unix Biker
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: String To Float
Then str(LED[-2]) doesn't return what you think it does. Insert a print call to check its value and whether the substring from char 6 (zero-based) is a valid float representation - and nothing else or anything else after it.