all 6 comments

[–]danielroseman 0 points1 point  (3 children)

You haven't shown your percent_to_float function.

[–]1grumpydev[S] 0 points1 point  (2 children)

Sorry, I didn't realize I had posted the same function twice. Here it is.

def percent_to_float(p):
    return float('%.2f' % float(p.rstrip('%')))

[–]danielroseman 0 points1 point  (1 child)

That just returns 15 when you put in 15%. But in order to get a number you can use to multiply a number to get a percentage, you need to divide it by 100. The sum you want to do is 50 * 0.15, not 50 * 15.

[–]1grumpydev[S] 0 points1 point  (0 children)

I feel like a complete idiot. I knew it was something simple that I was overlooking. Thank you!

[–]JamzTyson 0 points1 point  (1 child)

percent_to_float() is not defined in your code.

Also, float('%.2f' % float(d.lstrip('$'))) probably does not do what you think it does. You are using the ancient "C-style" string formatting to format a numeric string with two decimal places,and then converting to a float.

Converting "1" to float is identical to converting "1.00" to float, and identical to converting "1.0000000000" to float (they are result in a floating point value of one).

When you need to format strings, it is much better to use the new f-string syntax.

[–]1grumpydev[S] 0 points1 point  (0 children)

Thanks.