为什么此Golang代码无法将字符串转换为整数? [英] Why is this Golang code to convert a string to an integer failing?

查看:74
本文介绍了为什么此Golang代码无法将字符串转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单:

strconv.Atoi("1250000.0000")

这会导致错误:

0 strconv.ParseInt:解析"1250000.0000":语法无效

0 strconv.ParseInt: parsing "1250000.0000": invalid syntax

有任何线索吗?

推荐答案

Atoi 仅适用于可解析为整数的字符串.

Atoi works only for strings that can be parsed as integers.

您需要的是 parseFloat

这篇关于为什么此Golang代码无法将字符串转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆