douchixu3686 2017-06-14 12:56
浏览 19

最大浮线宽度

In go, the statement

fmt.Sprintf("%4.3f", 18.8836)

Will return

18.883

Is there a way of making the return value

18.88

In other words, is there a way to make the 4 apply to the whole width of the number and not just the decimal portion?

  • 写回答

1条回答 默认 最新

  • donglu9872 2017-06-14 12:59
    关注

    You can accomplish this with %g:

    fmt.Printf("%.4g
    ", 18.8836)
    

    https://play.golang.org/p/accWeNXG9V

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部