我无法将混合字母和数字的字符串转换为带(或不带)小数的数字。字符串不一定是99,50,但也可以是任何其他字符串表示的数字。小数点分隔符也可以.代替,.
我尝试了以下(游乐场链接):
package main
import (
"fmt"
"strconv"
)
func main() {
price := "99,50 SEK"
res1, _ := strconv.Atoi(price)
fmt.Println(res1)
res2, _ := strconv.ParseInt(price, 10, 64)
fmt.Println(res2)
res3, _ := strconv.ParseFloat(price, 64)
fmt.Println(res3)
}
我从他们那里得到的输出是这样的:
0
我想要的输出是这样的:
99.50
也可以接受的是:
99
米琪卡哇伊
相关分类