Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
fmt: %x on Stringer gives unintuitive results when value is an integer. #4754
This is a tough one but I'm inclined to leave things alone. 'x' is an integer format but it's also a string format and the code says: "If a string is acceptable according to the format, see if the value satisfies [error or Stringer]". If 'x' becomes integer in this context, then I need to think about other non-string formats like %g, and I think it just gets more complicated. Also, making the change could possibly break code that wants to hexify the String result, which is reasonable itself. In short, I will mark this WorkingAsIntended because, although the proposal is reasonable, so is the existing behavior. To get the behavior you ask for, it's easy and arguably clearer to convert: fmt.Printf("decimal: %d; hex %x\n", int(d), int(d))
Status changed to WorkingAsIntended.