Convert a percentage string (e.g. "99.8%") to Float64 when extracting data from CSV

Maybe one could write a small package to implement a Percent type, and make it possible to do

parse(Percent{Float64}, "99.5%")

Parsing CSV would then work as long as the user specifies which columns should be parsed as this type. A missing “%” at the end of the string would then be a parse error.

(The division by 100 should not happen until converting to another numeric type, since 1//100 is not exactly representable in floating-point.)

4 Likes