- Extract identical numericOnly inline functions from powerball and megamillions into shared sites/internal/parse.NumericOnly with tests - Extract duplicated DuckDuckGo result parsing from Search() and GetResults() into shared extractResults() helper Closes #13, #14 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
22 lines
405 B
Go
22 lines
405 B
Go
package parse
|
|
|
|
import "strconv"
|
|
|
|
// NumericOnly extracts only digits and decimal points from a string and
|
|
// returns the result as a float64. Returns 0 if parsing fails.
|
|
func NumericOnly(in string) float64 {
|
|
var out string
|
|
for _, r := range in {
|
|
if (r >= '0' && r <= '9') || r == '.' {
|
|
out += string(r)
|
|
}
|
|
}
|
|
|
|
val, err := strconv.ParseFloat(out, 64)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
return val
|
|
}
|