diff --git a/formatting/formatting.go b/formatting/formatting.go new file mode 100644 index 0000000..ffef30a --- /dev/null +++ b/formatting/formatting.go @@ -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) +} diff --git a/main.go b/main.go index c1416c0..d3f5286 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,8 @@ package main // import "git.sangeeth.dev/gobyexample/panic" // import "git.sangeeth.dev/gobyexample/defers" // 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() { // runes.Runes() @@ -47,5 +48,6 @@ func main() { // panic.Panic() // defers.Defers() // recovering.Recover() - stringfuncs.StringFuncs() + // stringfuncs.StringFuncs() + formatting.Formatting() }