79713494

Date: 2025-07-24 14:02:55
Score: 1
Natty:
Report link

How to write isNumeric function in Golang?

@Tiago César Oliveira mentioned "Inf" or "infinity", so "NaN" could be a problem too.
Mixed it all together (only want numbers, nothing else).

func IsNumeric(s string) bool {
    value, err := strconv.ParseFloat(s, 64)
    if err != nil {
        return false
    }

    return !(math.IsInf(value, 0) || math.IsNaN(value))
}
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @Tiago
  • Low reputation (0.5):
Posted by: Robert