File tree 2 files changed +24
-23
lines changed
examples/string-formatting
2 files changed +24
-23
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ func main() {
50
50
51
51
// There are also several formatting options for
52
52
// floats. For basic decimal formatting use `%f`.
53
- fmt .Printf ("%f" , 78.9 )
53
+ fmt .Printf ("%f\n " , 78.9 )
54
54
55
55
// `%e` and `%E` format the float in (slightly
56
56
// different versions of) scientific notation.
@@ -99,7 +99,7 @@ func main() {
99
99
// So far we've seen `Printf`, which prints the
100
100
// formatted string to `os.Stdout`. `Sprintf` formats
101
101
// and returns a string without printing it anywhere.
102
- s := fmt .Sprintf ("a %s " , "string" )
102
+ s := fmt .Sprintf ("a %s" , "string" )
103
103
fmt .Println (s )
104
104
105
105
// You can format+print to `io.Writers` other than
Original file line number Diff line number Diff line change 1
- $ go run string-formatting.go
2
- {1 2}
3
- {x:1 y:2}
4
- main.point{x:1, y:2}
5
- main.point
6
- true
7
- 123
8
- 1110
9
- !
10
- 1c8
11
- 78.9000001.234000e+08
12
- 1.234000E+08
13
- " string"
14
- " \" string\" "
15
- 6865782074686973
16
- 0x42134100
17
- | 12| 345|
18
- | 1.20| 3.45|
19
- | 1.20 | 3.45 |
1
+ $ go run string-formatting.go
2
+ {1 2}
3
+ {x:1 y:2}
4
+ main.point{x:1, y:2}
5
+ main.point
6
+ true
7
+ 123
8
+ 1110
9
+ !
10
+ 1c8
11
+ 78.900000
12
+ 1.234000e+08
13
+ 1.234000E+08
14
+ " string"
15
+ " \" string\" "
16
+ 6865782074686973
17
+ 0x42135100
18
+ | 12| 345|
19
+ | 1.20| 3.45|
20
+ | 1.20 | 3.45 |
20
21
| foo| b|
21
22
| foo | b |
22
- a string
23
- an error
23
+ a string
24
+ an error
You can’t perform that action at this time.
0 commit comments