Skip to content

Commit 020c97e

Browse files
committed
Add int_to_str.go
1 parent 656389f commit 020c97e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

internal/examples/basic/convert/examples.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ func NewRegister() mappings.Register {
1515

1616
// Regist -- 登録します.
1717
func (r *register) Regist(m mappings.ExampleMapping) {
18-
m["string_slice_to_interface_slice"] = StringSliceToInterfaceSlice
18+
m["convert_string_slice_to_interface_slice"] = StringSliceToInterfaceSlice
19+
m["convert_int_to_str"] = IntToStr
1920
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package convert
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/devlights/gomy/output"
7+
)
8+
9+
// IntToStr は、fmt.Sprint() を使って、数値 (int) を 文字列 (string) に変換するサンプルです.
10+
//
11+
// REFERENCES:
12+
// - https://dave.cheney.net/2018/07/12/slices-from-the-ground-up
13+
func IntToStr() error {
14+
var (
15+
i int = 100
16+
f float32 = 12.345
17+
)
18+
19+
s := fmt.Sprint(i)
20+
output.Stdoutf("[int to str]", "%[1]v(%[1]T) --> %[2]q(%[2]T)\n", i, s)
21+
22+
s = fmt.Sprint(f)
23+
output.Stdoutf("[float to str]", "%[1]v(%[1]T) --> %[2]q(%[2]T)\n", f, s)
24+
25+
return nil
26+
}

0 commit comments

Comments
 (0)