http://play.golang.org/p/3mjFDTTOXG
printf int is ok, but with float, I got no leading zero.
fmt.Printf("%03.6f
", 1.234)
>1.234000
Why this happen ?How to make the leading zero display ?
golang v1.4.1
EDIT
I figured it out
fmt.Printf("%010.6f
", 1.234)
this is ok now.
EDIT
from https://golang.org/pkg/fmt/
Width and precision are measured in units of Unicode code points, that is, runes. (This differs from C's printf where the units are always measured in bytes.) Either or both of the flags may be replaced with the character '*', causing their values to be obtained from the next operand, which must be of type int.
The reason is that you set 6 as the precision of the string that will be printed and only 3 as the width. From the fmt package.
Width is specified by an optional decimal number immediately following the verb. If absent, the width is whatever is necessary to represent the value. Precision is specified after the (optional) width by a period followed by a decimal number. If no period is present, a default precision is used.
...
0 pad with leading zeros rather than spaces;
for numbers, this moves the padding after the sign
Thus you get 1.234000. To get leading 0s you need to increase the width of the string past 8 (length of 1 + . + 234000). So with %09.6f
you'll get 01.234000