有一个项目如下,使用了github.com/shopspring/decimal这个第三方的库

package main

import (
	"fmt"

	"github.com/shopspring/decimal"
)

func main() {
	d := decimal.NewFromFloat(3.14159266667765)
	// 现在d可以精确表示这个小数,但它的字符串表示形式取决于你如何格式化它
	s := d.String()
	fmt.Println(s) // 输出:3.14159266667765
}

需要在当前项目目录下初始化一个go.mod文件

go mod init demo08

然后再次执行

go get github.com/shopspring/decimal

go.mod下就会被写入以下内容

module demo08

go 1.20

require github.com/shopspring/decimal v1.3.1 // indirect

这时候就可以正常运行程序了