[go-nuts] Re: Golang formating of alternate form with zero padding

2024-02-03 Thread 'Brian Candler' via golang-nuts
Admittedly, C and Python work the same way, which is different to Go. #include int main(void) { printf("%07x\n", 42); printf("%0#7x\n", 42); printf("0x%07x\n", 42); return 0; } // Output 02a 0x0002a 0x02a On Wednesday 31 January 2024 at 13:56:07 UTC Brian Candler wrote:

[go-nuts] Re: Golang formating of alternate form with zero padding

2024-01-31 Thread 'Brian Candler' via golang-nuts
https://pkg.go.dev/fmt#hdr-Printing The '#' means you want the alternate format with the 0x prepended, and the '7' means you want the number itself padded to 7 digits x := fmt.Sprintf("%07x", 42) // 02a y := fmt.Sprintf("%0#7x", 42) // 0x02a z := fmt.Sprintf("0x%07x", 42) // 0x000