将字符串转换为float32吗?

There is an input that I need to read from the console as a string, then manipulate the string and convert some of it to float32.

I have tried using:

float, _ := strconv.ParseFloat(myString, 32)

But it does not work. This is the error I get:

cannot use float (type float64) as type float32 in field value

Is there anything else I could do? Thanks!

float has the type float32, but strconv.ParseFloat returns float64. All you need to do is convert the result:

// "var float float32" up here somewhere
value, err := strconv.ParseFloat(myString, 32)
if err != nil {
    // do something sensible
}
float = float32(value)

Depending on the situation, it may be better to change float's type to float64.