DemocracyClub / yournextrepresentative

👥 A website for crowd-sourcing structured election candidate data
https://candidates.democracyclub.org.uk
GNU Affero General Public License v3.0
21 stars 27 forks source link

Handle non-numeric symbols before rounding #2428

Closed VirginiaDooley closed 1 month ago

VirginiaDooley commented 1 month ago

This fixes a previous PR that sought to remove decimals and round percentages to the nearest whole number. This commit rounded before removing, resulting in a greater than expected result such as 50.55 becomes 5055.

This change refactors the order of operations and handles non-numeric symbols before rounding percentages to the nearest whole number

symroe commented 1 month ago

This works for 45.5 -> 46, but 54% goes to NaN as does 12,34 -> NaN.

Clearly 12,34 isn't correct as a percent, but I think it shouldn't convert to NaN in this case. Can we change the regex to match replace any non-numeric or non-.?