在我對 go fmt 包的菜鳥理解中,我遇到了一些問題它與以下代碼有關:導入“fmt”func main() { var smallFloat float64 = 0.123456789 var bigFloat float64 = 123456789000 fmt.Println(fmt.Sprintf("%f", smallFloat)) fmt.Println(fmt.Sprintf("%f", bigFloat))}輸出是:0.123457123456789000.000000我不想使用科學記數法,所以認為 %f 適合我的需要。我可以從格式頁面(https://golang.org/pkg/fmt/)看到它說:The default precision for %e and %f is 6; for %g it is the smallest number of digits necessary to identify the value uniquely.有沒有一種方法可以使用 fmt 包,它允許我表示 smallFloat 的完整十進制值,同時不在 bigFloat 的末尾附加 6 個零?
轉到 fmt float64 問題
慕田峪9158850
2021-12-20 16:23:43
