2825 explained code solutions for 75 technologies


golangHow to format integer


package main
import "fmt"

func main() {
  res := fmt.Sprintf("Number: %10d", 123)
  fmt.Println(res)
}ctrl + c
package main

default package declaration

import "fmt"

loads fmt package to operate on strings (and print them)

fmt.Sprintf(

formats given string based on a given template and return result

%10d

sample number formatting placeholder, will pad number to 10 spaces on the left

123

sample integer value to format

res

variable will contain formatted value