go - How to write isNumeric function in Golang? -


i want check if string numeric. example, "abcd123" should return false. "1.4" or "240" should return true. thinking of using strconv parseint , parsefloat not sure if right way.

i thinking of using strconv parseint , parsefloat not sure if right way.

well, it's a right way.

you don't need use parseint, though. parsefloat job.

func isnumeric(s string) bool {     _, err := strconv.parsefloat(s, 64)     return err == nil } 

see example here: https://play.golang.org/p/d53hrs-kil


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -