2021年5月7日星期五

Golang fmt printf right padding

I have this code to create a pyramid of numbers and zeroes based on the given inputs.

inputs := []int{1, 3, 4, 5, 6, 7, 9}  for idx, input := range inputs {      fmt.Printf("%0*d\n", len(inputs)-idx, input)  }  

Which outputs: 0000001 000003 00004 0005 006 07 9

But the designated output is: 1000000 300000 40000 5000 600 70 9

how can I achieve that? when I tried the "%0-*d\n" it only pad the spaces and the zeroes does not appear.

https://stackoverflow.com/questions/67443444/golang-fmt-printf-right-padding May 08, 2021 at 10:05AM

没有评论:

发表评论