Skip to content

Commit 183acda

Browse files
committed
update str2float
1 parent 46f8bb0 commit 183acda

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

samples/functional/do_reduce.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def str2int(s):
4040

4141
def str2float(s):
4242
nums = map(lambda ch: CHAR_TO_FLOAT[ch], s)
43-
point = -1
43+
point = 0
4444
def to_float(f, n):
4545
nonlocal point
4646
if n == -1:
47-
point = 0
47+
point = 1
4848
return f
49-
if point == -1:
49+
if point == 0:
5050
return f * 10 + n
5151
else:
52-
point = point + 1
53-
return f + n / pow(10, point)
52+
point = point * 10
53+
return f + n / point
5454
return reduce(to_float, nums, 0.0)
5555

5656
print(str2float('0'))

0 commit comments

Comments
 (0)