Printf

138 views
Skip to first unread message

Juan Mamani

unread,
Feb 2, 2024, 11:55:49 AM2/2/24
to golang-nuts
Hi everybody!

I was checking consistency  behavior of fmt.Printf with some basic samples. And for my surprise never expected what I found.

My context:
OS: Linux, debian 8,9,10,11
Go version 1.21

What I was doing? Learning about fmt.Printf
Expecting fmt.Printf behavior be the same output for any use case.

Source code: https://go.dev/play/p/oKifC9Lw-JO


Ouput:
g_x 15.925999599999999
15.91.6241.624            <----- for me this is freaking weird ouput
--------------
x2: 1.624
x2: 1.624
x1: 15.9259996
--------------
j: 4
k: 5
p: 1.624

May be I found compiler bug?  Can someone help me to figure out what is going on.

Thank you for your attention

Kurtis Rader

unread,
Feb 2, 2024, 12:12:55 PM2/2/24
to Juan Mamani, golang-nuts
I think you're being confused by the lack of newlines in the output. Add "\n" to the end of the printf format.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Luca Pascali

unread,
Feb 2, 2024, 1:06:17 PM2/2/24
to Juan Mamani, golang-nuts
you forgot the \n in the printf format string

without it, next is written right after the end of the printf


Psk

--

Juan Mamani

unread,
Feb 3, 2024, 8:16:33 PM2/3/24
to golang-nuts
Kurtis, thanks for your reply. 

Juan Mamani

unread,
Feb 3, 2024, 8:18:38 PM2/3/24
to golang-nuts
Luca, thanks for your answerr
Reply all
Reply to author
Forward
0 new messages