Formatting numbers
If the numbers are converted to the string, they usually need to be reasonably formatted. The formatting of a number means the number is printed with a given number, made up of digits and decimals. The representation of a value can also be chosen. A closely related problem with this, however, is the localization of number formatting. For example, some languages use comma-separated zeros.
How to do it...
- Open the console and create the folder
chapter03/recipe05
. - Navigate to the directory.
- 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...