4

This should have been simple:

strconv.Atoi("1250000.0000")

This results in an error:

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

Any clues?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179

2 Answers2

13

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

What you need is parseFloat

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
1

What dystroy said is true, but keep in mind that floats are inprecise and you could get an incorrect answer that way. In your case you can simply split the string on the period and then use Atoi on that.

strconv.Atoi(strings.Split("1250000.0000", ".")[0])
justinas
  • 6,287
  • 3
  • 26
  • 36
  • You're missing the `, "."` in the params to `strings.Split()` (and fixing that is less than six chars change, so StackOverflow won't accept the edit) – Phil P Oct 09 '13 at 18:37