简体   繁体   English

如何在运行时连接字符串和float64?

[英]How to concat a string and float64 on go?

I am trying to solve this: http://tour.golang.org/#58 我正在尝试解决此问题: http : //tour.golang.org/#58

Here is what I have done; 这是我所做的;

#imports omitted
type ErrNegativeSqrt float64

func (e ErrNegativeSqrt) Error() string {
    return "Cannot Sqrt negative number: " + string(e)
}

func Sqrt(f float64) (float64, error) {
    if f < 0 {
        return 0, ErrNegativeSqrt(1)
    }
    # calculate z here...
    return z, nil
}
# main omitted

I have also tried e.String() and e.string() but those didn't work too... 我也尝试过e.String()e.string()但是这些也没有用...

Try using the fmt package 尝试使用fmt软件包

import "fmt"
...
return fmt.Sprint("Cannot Sqrt negative number ", float64(e))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM