Add formatting
This commit is contained in:
parent
ab676f25a6
commit
18da65a933
36
formatting/formatting.go
Normal file
36
formatting/formatting.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package formatting
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
var f = fmt.Printf
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
name string
|
||||||
|
age uint
|
||||||
|
}
|
||||||
|
|
||||||
|
func Formatting() {
|
||||||
|
p := Person{"Nadeshiko", 15}
|
||||||
|
|
||||||
|
f("int: %d\n", 5)
|
||||||
|
f("float: %f\n", 4)
|
||||||
|
f("float (scientific): %e\n", math.Pow(2, 32))
|
||||||
|
f("string: %s\n", "hello")
|
||||||
|
f("go value loose: %v\n", p)
|
||||||
|
f("go value strict: %+v\n", p)
|
||||||
|
f("go value verbose: %#v\n", p)
|
||||||
|
f("go bool: %t\n", true)
|
||||||
|
f("go type: %T\n", p)
|
||||||
|
f("go ptr address: %p\n", &p)
|
||||||
|
f("go hex string: %x\n", "foo")
|
||||||
|
f("go hex int: %x\n", 16)
|
||||||
|
f("go bin int: %b\n", 5)
|
||||||
|
f("go oct int: %o\n", 8)
|
||||||
|
f("go num width: |%5d|\n", 2)
|
||||||
|
f("go num width (left align): |%-5d|\n", 2)
|
||||||
|
f("go float precision (left align): |%-5.2f|\n", 3.141516)
|
||||||
|
f("go char: %c\n", 97)
|
||||||
|
}
|
6
main.go
6
main.go
@ -22,7 +22,8 @@ package main
|
|||||||
// import "git.sangeeth.dev/gobyexample/panic"
|
// import "git.sangeeth.dev/gobyexample/panic"
|
||||||
// import "git.sangeeth.dev/gobyexample/defers"
|
// import "git.sangeeth.dev/gobyexample/defers"
|
||||||
// import "git.sangeeth.dev/gobyexample/recovering"
|
// import "git.sangeeth.dev/gobyexample/recovering"
|
||||||
import "git.sangeeth.dev/gobyexample/stringfuncs"
|
// import "git.sangeeth.dev/gobyexample/stringfuncs"
|
||||||
|
import "git.sangeeth.dev/gobyexample/formatting"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// runes.Runes()
|
// runes.Runes()
|
||||||
@ -47,5 +48,6 @@ func main() {
|
|||||||
// panic.Panic()
|
// panic.Panic()
|
||||||
// defers.Defers()
|
// defers.Defers()
|
||||||
// recovering.Recover()
|
// recovering.Recover()
|
||||||
stringfuncs.StringFuncs()
|
// stringfuncs.StringFuncs()
|
||||||
|
formatting.Formatting()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user