O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe05.
  2. Navigate to the directory.
  3. Create the format.go file with the following content:
        package main        import (          "fmt"        )        var integer int64 = 32500        var floatNum float64 = 22000.456        func main() {          // Common way how to print the decimal          // number          fmt.Printf("%d \n", integer)          // Always show the sign          fmt.Printf("%+d \n", integer)          // Print in other base X -16, o-8, b -2, d - 10          fmt.Printf("%X \n", integer)          fmt.Printf("%#X \n", integer)          // Padding with leading zeros          fmt.Printf("%010d \n", integer)           // Left padding with spaces          fmt.Printf("% 10d \n", integer)          // Right padding          fmt.Printf("% -10d \n", integer)          // Print floating          // point number          fmt.Printf("%f \n", floatNum) // Floating-point ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required