How to use Sprintf to format a string in Go

2 Answers

0 votes
package main
  
import (
    "fmt"
)
  
func main() {
    const n1, n2, n3= 1, 7, 12
  
    s := fmt.Sprintf("%d + %d + %d = %d", n1, n2, n3, n1 + n2 + n3) 

    fmt.Println(s)
}
  
  
  
  
/*
run:
  
1 + 7 + 12 = 20
  
*/

 



answered May 27, 2020 by avibootz
0 votes
package main
  
import (
    "fmt"
)
  
func main() {
    s := fmt.Sprintf("Binary: %b - %b", 3, 255)

    fmt.Println(s)
}
  
  
  
  
/*
run:
  
Binary: 11 - 11111111
  
*/

 



answered May 27, 2020 by avibootz
...