go - How can I convert string to integer in golang -
i want convert string integer in golang. don't know format of string. example, "10" -> 10, "65.0" -> 65, "xx" -> 0, "11xx" -> 11, "xx11"->0
i searching , find strconv.parseint(). can not handle "65.0". have check string's format.
is there better way?
i believe function looking
strconv.parsefloat() see example here
but return type of function float64.
if don't need fractional part of number passed string following function job:
func strtoint(str string) (int, error) { nonfractionalpart := strings.split(str, ".") return strconv.atoi(nonfractionalpart[0]) }
Comments
Post a Comment