Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does printf leave an extra "%" after my output? [closed]

Tags:

go

I have this piece of code

a := 32
fmt.Printf("%d", a)

the output is

32%

when anyone would expect

32

Could it be a terminal effect? I am using zsh.

like image 597
Aakash Verma Avatar asked Sep 06 '25 03:09

Aakash Verma


1 Answers

The issue is that Printf doesn't add a newline. The '%' you are seeing is your bash / shell prompt.

Try this:

fmt.Printf("%d\n", 32)

The \n will add a newline, and your prompt will now be on the next line.

like image 152
craigmj Avatar answered Sep 07 '25 23:09

craigmj