RosettaCodeData/Task/Determine-if-a-string-is-numeric/Go/determine-if-a-string-is-numeric-1.go
2020-02-17 23:21:07 -08:00

19 lines
367 B
Go

package main
import (
"fmt"
"strconv"
)
func isNumeric(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
}
func main() {
fmt.Println("Are these strings numeric?")
strings := []string{"1", "3.14", "-100", "1e2", "NaN", "rose"}
for _, s := range strings {
fmt.Printf(" %4s -> %t\n", s, isNumeric(s))
}
}