How to format the printf function for variables with different datatypes in Go

1 Answer

0 votes
package main

import (
    "fmt"
)

func main() {
    fmt.Printf("bool: %t\n", true)
    fmt.Printf("int: %d\n", 9084)
    fmt.Printf("bin: %b\n", 15)
    fmt.Printf("char: %c\n", 97)
    fmt.Printf("hex: %X\n", 456)
    fmt.Printf("float: %f\n", 3.14)
    fmt.Printf("string: %s\n", "Golang")
}



/*
run:

bool: true
int: 9084
bin: 1111
char: a
hex: 1C8
float: 3.140000
string: Golang

*/

 



answered Dec 1, 2024 by avibootz

Related questions

2 answers 198 views
198 views asked Oct 24, 2020 by avibootz
2 answers 291 views
...