跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • go 语言 有很多位小数的 big.Float 转换成 string 类型如何不使用科学计数法。
未分類
21 9 月 2020

go 语言 有很多位小数的 big.Float 转换成 string 类型如何不使用科学计数法。

go 语言 有很多位小数的 big.Float 转换成 string 类型如何不使用科学计数法。

資深大佬 : rimutuyuan 5

res, _ := new(big.Float).SetString(“100000000000”)
res = res.Quo(res, big.NewFloat(1e18))
fmt.Println(res.String())

输出 1e-07

如何输出 0.000001 呢

大佬有話說 (2)

  • 資深大佬 : luwill

    https://golang.org/src/math/big/ftoa.go

    读一下 math/big 的源代码,你会发现 String 调用的 Text 方法。
    “`
    // String formats x like x.Text(‘g’, 10).
    // (String must be called explicitly, Float.Format does not support %s verb.)
    func (x *Float) String() string {
    return x.Text(‘g’, 10)
    }
    “`
    Text 支持 formt 参数,你要的`res.Text(‘f’, 10)`

    // ‘f’ -ddddd.dddd, no exponent

  • 資深大佬 : lysS

    你可以用这个
    a := 0.0000001
    fmt.Println(strconv.FormatFloat(float64(a), ‘f’, 9, 64))
    //
    0.000000100

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具