Reputation: 18821
I'm just going through tutorials of GoLang because I'm curious to learn a more general language (only know javascript). Tut
I dont understand whats happening with %g and math.Nextafter
means? After reviewing the documentation it helps little.
Question:
Could anyone give me a better overview of the %g
syntax and nextafter()
method; perhaps a digestible usecase?? Here's links to documentation:fmt // nextAfter
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Now you have %G problems.",
math.Nextafter(2, 3))
}
Upvotes: 1
Views: 1395
Reputation: 1328792
Regarding the %g syntax, see 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
The float64
returned by NextAfter()
will be presented using the scientific notation or decimal point, depending on which is more compact.
For the returned value of NextAfter, see "Why does math.Nextafter(2,3) in Go increment by 0.0000000000000004 instead of 0.0000000000000001?"
You will see plenty of Go string formatting in "Go by Example: String Formatting": one parameter for the format, one for the value to be formatted.
Those formats ("verb") are listed in `pkg/fmt/.
Upvotes: 4