gpt4 book ai didi

GoLang nextafter & %g?

转载 作者:IT王子 更新时间:2023-10-29 01:59:41 26 4
gpt4 key购买 nike

我正在学习 GoLang 的教程,因为我很想学习一种更通用的语言(只知道 javascript)。 Tut

我不明白 %g 和 math.Nextafter 是什么意思?在查看文档后,它帮助不大。

问题:谁能给我一个关于 %g 语法和 nextafter() 方法的更好的概述;也许是一个易于理解的用例??以下是文档链接:fmt//nextAfter

package main

import (
"fmt"
"math"
)

func main() {
fmt.Printf("Now you have %G problems.",
math.Nextafter(2, 3))
}

最佳答案

关于 %g 语法,参见 fmt syntax :

%g  whichever of %e or %f produces more compact output
%e scientific notation, e.g. -1234.456e+78
%f decimal point but no exponent, e.g. 123.456

NextAfter() 返回的float64 将使用科学计数法或小数点表示,具体取决于哪个更紧凑。

NextAfter的返回值见“Why does math.Nextafter(2,3) in Go increment by 0.0000000000000004 instead of 0.0000000000000001?

你会在“Go by Example: String Formatting”中看到大量的 Go 字符串格式化:一个参数用于格式,一个用于要格式化的值。
这些格式(“动词”)在 `pkg/fmt/ 中列出。

关于GoLang nextafter & %g?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27216886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com