~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/fmt/doc.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
                %e      scientific notation, e.g. -1234.456e+78
38
38
                %E      scientific notation, e.g. -1234.456E+78
39
39
                %f      decimal point but no exponent, e.g. 123.456
 
40
                %F      synonym for %f
40
41
                %g      whichever of %e or %f produces more compact output
41
42
                %G      whichever of %E or %f produces more compact output
42
43
        String and slice of bytes:
50
51
        There is no 'u' flag.  Integers are printed unsigned if they have unsigned type.
51
52
        Similarly, there is no need to specify the size of the operand (int8, int64).
52
53
 
53
 
        The width and precision control formatting and are in units of Unicode
54
 
        code points.  (This differs from C's printf where the units are numbers
 
54
        Width is specified by an optional decimal number immediately following the verb.
 
55
        If absent, the width is whatever is necessary to represent the value.
 
56
        Precision is specified after the (optional) width by a period followed by a
 
57
        decimal number. If no period is present, a default precision is used.
 
58
        A period with no following number specifies a precision of zero.
 
59
        Examples:
 
60
                %f:    default width, default precision
 
61
                %9f    width 9, default precision
 
62
                %.2f   default width, precision 2
 
63
                %9.2f  width 9, precision 2
 
64
                %9.f   width 9, precision 0
 
65
 
 
66
        Width and precision are measured in units of Unicode code points.
 
67
        (This differs from C's printf where the units are numbers
55
68
        of bytes.) Either or both of the flags may be replaced with the
56
69
        character '*', causing their values to be obtained from the next
57
70
        operand, which must be of type int.
58
71
 
59
 
        For numeric values, width sets the minimum width of the field and
 
72
        For most values, width is the minimum number of characters to output,
 
73
        padding the formatted form with spaces if necessary.
 
74
        For strings, precision is the maximum number of characters to output,
 
75
        truncating if necessary.
 
76
 
 
77
        For floating-point values, width sets the minimum width of the field and
60
78
        precision sets the number of places after the decimal, if appropriate,
61
79
        except that for %g/%G it sets the total number of digits. For example,
62
80
        given 123.45 the format %6.2f prints 123.45 while %.4g prints 123.5.
63
81
        The default precision for %e and %f is 6; for %g it is the smallest
64
82
        number of digits necessary to identify the value uniquely.
65
83
 
66
 
        For most values, width is the minimum number of characters to output,
67
 
        padding the formatted form with spaces if necessary.
68
 
        For strings, precision is the maximum number of characters to output,
69
 
        truncating if necessary.
 
84
        For complex numbers, the width and precision apply to the two
 
85
        components independently and the result is parenthesized, so %f applied
 
86
        to 1.2+3.4i produces (1.200000+3.400000i).
70
87
 
71
88
        Other flags:
72
89
                +       always print a sign for numeric values;
98
115
                fmt.Printf("%v\n", i)
99
116
        will print 23.
100
117
 
101
 
        If an operand implements interface Formatter, that interface
102
 
        can be used for fine control of formatting.
 
118
        Except when printed using the verbs %T and %p, special
 
119
        formatting considerations apply for operands that implement
 
120
        certain interfaces. In order of application:
 
121
 
 
122
        1. If an operand implements the Formatter interface, it will
 
123
        be invoked. Formatter provides fine control of formatting.
 
124
 
 
125
        2. If the %v verb is used with the # flag (%#v) and the operand
 
126
        implements the GoStringer interface, that will be invoked.
103
127
 
104
128
        If the format (which is implicitly %v for Println etc.) is valid
105
 
        for a string (%s %q %v %x %X), the following two rules also apply:
106
 
 
107
 
        1. If an operand implements the error interface, the Error method
108
 
        will be used to convert the object to a string, which will then
109
 
        be formatted as required by the verb (if any).
110
 
 
111
 
        2. If an operand implements method String() string, that method
112
 
        will be used to convert the object to a string, which will then
113
 
        be formatted as required by the verb (if any).
 
129
        for a string (%s %q %v %x %X), the following two rules apply:
 
130
 
 
131
        3. If an operand implements the error interface, the Error method
 
132
        will be invoked to convert the object to a string, which will then
 
133
        be formatted as required by the verb (if any).
 
134
 
 
135
        4. If an operand implements method String() string, that method
 
136
        will be invoked to convert the object to a string, which will then
 
137
        be formatted as required by the verb (if any).
 
138
 
 
139
        For compound operands such as slices and structs, the format
 
140
        applies to the elements of each operand, recursively, not to the
 
141
        operand as a whole. Thus %q will quote each element of a slice
 
142
        of strings, and %6.2f will control formatting for each element
 
143
        of a floating-point array.
114
144
 
115
145
        To avoid recursion in cases such as
116
146
                type X string